Irregular OCR inference time for the same image in a loop (docTr vs. onnxTr) #1828
Closed
govindbagaria
started this conversation in
General
Replies: 2 comments 1 reply
-
Hi @govindbagaria 👋🏼, Thanks for reporting I will have a deeper look after my vacation (06.01.) 👍 Best, |
Beta Was this translation helpful? Give feedback.
0 replies
-
The issue might be because of the kernels taking up much resources in my system. Not able to replicate the same on anther device. Marking this as not relevant for now. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@felixdittrich92 Hello,
I’m experiencing irregular inference times when I repeatedly run OCR on the same image in a loop. The memory profile remains pretty constant, but the time taken to process each iteration varies significantly—even though I’m feeding the exact same image each time.
I’ve tried this with both onnxTr and docTr, each set up to disable multiprocessing and set a small primitive cache capacity. Below are my minimal reproducible scripts, plus screenshots of the resulting time profiles and memory usage.
onnxTr Code:
``
import os
os.environ["ONNXTR_MULTIPROCESSING_DISABLE"] = "TRUE"
os.environ["ONEDNN_PRIMITIVE_CACHE_CAPACITY"] = "1"
os.environ["ONNXTR_CACHE_DIR"] = "onxx_models"
import time
import tqdm
import matplotlib.pyplot as plt
from onnxtr.io import DocumentFile
from onnxtr.models import ocr_predictor
model = ocr_predictor(
det_arch="db_mobilenet_v3_large",
reco_arch="crnn_vgg16_bn",
assume_straight_pages=False,
straighten_pages=True
)
times = []
file_path = "img.jpg"
for i in tqdm.tqdm(range(0, 100)):
start_time = time.time()
doc = DocumentFile.from_images(file_path)
result = model(doc)
end_time = time.time()
inference_time = end_time - start_time
times.append(inference_time)
plt.figure(figsize=(8, 5))
plt.plot(range(0, 100), times, marker='o', linestyle='-', color='b', label='Inference Time')
plt.title('OCR Inference Time per Iteration (onnxTr)')
plt.xlabel('Iteration')
plt.ylabel('Time (seconds)')
plt.legend()
plt.grid(True)
plt.savefig('onnxTr_loop.png', dpi=150, bbox_inches='tight')
``
docTr Code:
``
import os
os.environ["DOCTR_MULTIPROCESSING_DISABLE"] = "TRUE"
os.environ["ONEDNN_PRIMITIVE_CACHE_CAPACITY"] = "1"
import time
import tqdm
import matplotlib.pyplot as plt
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
model = ocr_predictor(
det_arch="db_mobilenet_v3_large",
reco_arch="crnn_vgg16_bn",
pretrained=True,
assume_straight_pages=False,
straighten_pages=True
)
times = []
file_path = "img.jpg"
for i in tqdm.tqdm(range(0, 100)):
start_time = time.time()
doc = DocumentFile.from_images(file_path)
result = model(doc)
end_time = time.time()
inference_time = end_time - start_time
times.append(inference_time)
plt.figure(figsize=(8, 5))
plt.plot(range(0, 100), times, marker='o', linestyle='-', color='b', label='Inference Time')
plt.title('OCR Inference Time per Iteration (docTr)')
plt.xlabel('Iteration')
plt.ylabel('Time (seconds)')
plt.legend()
plt.grid(True)
plt.savefig('docTr_loop.png', dpi=150, bbox_inches='tight')
``
Observations
Screenshots
![docTr_mem](https://private-user-images.githubusercontent.com/11533209/398406484-db24c714-ee52-4462-ba44-c0d8945b91a0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTg1OTgsIm5iZiI6MTczOTM1ODI5OCwicGF0aCI6Ii8xMTUzMzIwOS8zOTg0MDY0ODQtZGIyNGM3MTQtZWU1Mi00NDYyLWJhNDQtYzBkODk0NWI5MWEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMDQ1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThiOTljNDAwYjUzMThjOGZlZjAxNjgxOTU5ZWZmYjI3YzQxODNlYTVhNzE4YTUyODliODdlN2E4ZTVjZTMwMmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.HAKbX8J2fHHpEKgGd73oCbLrujxa_npQGKHwZd44GlU)
![docTr_loop](https://private-user-images.githubusercontent.com/11533209/398406518-13509c1e-b7b5-492c-bab1-9b17e908726c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTg1OTgsIm5iZiI6MTczOTM1ODI5OCwicGF0aCI6Ii8xMTUzMzIwOS8zOTg0MDY1MTgtMTM1MDljMWUtYjdiNS00OTJjLWJhYjEtOWIxN2U5MDg3MjZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMDQ1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQyNDFkZTUxMTdmOTMwMDk0MzE2NjM4OGI2MTM0YTRlNzgxZmQ3MTMzNDdiYWM3NmI0MjUzZDQzM2YyMDFiOWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2k0Bt-Q2ux7SVqaclcAAAMQWE91VpewW_7x19hU5h5k)
docTr Memory Profiling:
docTr Time Profiling:
onnxTr Memory Profiling:
![onnxTr_mem](https://private-user-images.githubusercontent.com/11533209/398406757-95a91d43-2b70-4a4e-8112-dc51668f3f4b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTg1OTgsIm5iZiI6MTczOTM1ODI5OCwicGF0aCI6Ii8xMTUzMzIwOS8zOTg0MDY3NTctOTVhOTFkNDMtMmI3MC00YTRlLTgxMTItZGM1MTY2OGYzZjRiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMDQ1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk1MDNhN2FkOWUwODBiNDFkZWIyMGMyM2MwOTEzMzBmMTM4YjE0NDdiZjExM2I5YjQwMmIyYWY3N2JjMjZhOTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.JI9BcdjgZGJn_t3Rrkyxsm2meMbADS90q-EpGvn7DB0)
![onnxTr_loop](https://private-user-images.githubusercontent.com/11533209/398406790-13df0a2c-59df-426b-8343-7bbe9c83e228.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTg1OTgsIm5iZiI6MTczOTM1ODI5OCwicGF0aCI6Ii8xMTUzMzIwOS8zOTg0MDY3OTAtMTNkZjBhMmMtNTlkZi00MjZiLTgzNDMtN2JiZTljODNlMjI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMDQ1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ3MGVlNjU1YWJhZTM1ZTIyMmU5MzEzOTQwYTNiNDgzZDg5ZTliZWFkMDYzNDI2YzU5ZmI0YWZkYWY1Nzk5ODMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jxJUSA1aEWSQizJy0609RObq42aoJ1xIdZyZJgGxy7Q)
onnxTr Time Profiling:
Questions
System Info
OS: macOS
Processor: 2.6 GHz 6-Core Intel Core i7
Graphics: AMD Radeon Pro 5300M 4 GB----Intel UHD Graphics 630 1536 MB
Python Version: 3.10
docTr Version: v0.10.0
onnxTr Version: v0.6.0
Beta Was this translation helpful? Give feedback.
All reactions