Inference gpu requirements #797
-
May i know how much gpu ram is required to inference from model? %matplotlib inline
import os
# Let's pick the desired backend
# os.environ['USE_TF'] = '1'
os.environ['USE_TORCH'] = '1'
import matplotlib.pyplot as plt
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
doc = DocumentFile.from_pdf("IOA.pdf").as_images()
print(f"Number of pages: {len(doc)}")
predictor = ocr_predictor(pretrained=True, )
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
predictor.half().to(device)
doc[0] = torch.tensor(doc[0]).to(device)
result = predictor(doc) It's gives me cuda out of memory. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @kumar-rajwnai 👋 My apologies for the late reply! Apart from that, early answers/remarks:
%matplotlib inline
import os
# Let's pick the desired backend
os.environ['USE_TORCH'] = '1'
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
import torch
doc = DocumentFile.from_pdf("IOA.pdf").as_images()
print(f"Number of pages: {len(doc)}")
predictor = ocr_predictor(pretrained=True)
# On CPU
result = predictor(doc) For the GPU part, I just opened #808 to make it simpler for users: once merged, you will only have to add Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hello @kumar-rajwnai 👋
My apologies for the late reply!
This looks more like a bug report, would you mind sharing details about your environment? (by pasting the results of running this script https://github.com/mindee/doctr/blob/main/scripts/collect_env.py)
Apart from that, early answers/remarks:
.half()
which only switch to fp16, and instead use a contextwith torch.cuda.autocast
as described here https://pytorch.org/docs/stable/notes/amp_examples.html