models.py 735 B

1234567891011121314151617181920212223242526272829303132
  1. from module.base.decorator import cached_property
  2. from module.ocr.ppocr import TextSystem
  3. class OcrModel:
  4. @cached_property
  5. def ch(self):
  6. return TextSystem()
  7. OCR_MODEL = OcrModel()
  8. if __name__ == "__main__":
  9. model = OCR_MODEL.ch
  10. import cv2
  11. import time
  12. from memory_profiler import profile
  13. image = cv2.imread(r"E:\Project\OnmyojiAutoScript-assets\jade.png")
  14. # 引入ocr 会导致非常巨大的内存开销
  15. @profile
  16. def test_memory():
  17. for i in range(10):
  18. start_time = time.time()
  19. result = model.detect_and_ocr(image)
  20. print(result)
  21. end_time = time.time()
  22. print(f'耗时:{end_time-start_time}')
  23. test_memory()