解决办法:可以考虑换低版本的模型。在paddleocr.py中可以看到有--ocr_version的参数。
parser.add_argument(
"--ocr_version",
type=str,
choices=SUPPORT_OCR_MODEL_VERSION,
default="PP-OCRv4",
help="OCR Model version, the current model support list is as follows: "
"1. PP-OCRv4/v3 Support Chinese and English detection and recognition model, and direction classifier model"
"2. PP-OCRv2 Support Chinese detection and recognition model. "
"3. PP-OCR support Chinese detection, recognition and direction classifier and multilingual recognition model.",
)
继续往下翻,可以看到:
if params.ocr_version in ["PP-OCRv3", "PP-OCRv4"]:
params.rec_image_shape = "3, 48, 320"
else:
params.rec_image_shape = "3, 32, 320"
在v3和v4之后,paddleocr增大了rec_image_shape,这也要求更大的显存。
因此可以在调用时增加ocr_version参数,达到使用更小的显存的目的。
PaddleOCR(use_angle_cls=True,use_gpu=True,lang="ch",show_log=False,ocr_version="PP-OCRv2")
切换版本后我便可以运行了。