mirror of
https://github.com/RapidAI/RapidOCR.git
synced 2026-11-10 21:10:55 +08:00
chore: update files
This commit is contained in:
1 parent
5bf7702915
commit
afbb6cbfd3
13 files changed
+185
-6706
No files matched your search
+4
-4
@@ -3,10 +3,10 @@
|
||||
# @Contact: liekkaskono@163.com
|
||||
import cv2
|
||||
|
||||
# from rapidocr_onnxruntime import RapidOCR, VisRes
|
||||
from rapidocr_torch import RapidOCR, VisRes
|
||||
from rapidocr import RapidOCR, VisRes
|
||||
|
||||
# from rapidocr import RapidOCR, VisRes
|
||||
# from rapidocr_onnxruntime import RapidOCR, VisRes
|
||||
# from rapidocr_torch import RapidOCR, VisRes
|
||||
|
||||
|
||||
# from rapidocr_paddle import RapidOCR, VisRes
|
||||
@@ -15,7 +15,7 @@ from rapidocr_torch import RapidOCR, VisRes
|
||||
# yaml_path = "tests/test_files/config.yaml"
|
||||
# engine = RapidOCR(config_path=yaml_path)
|
||||
|
||||
engine = RapidOCR(params={"Global.with_paddle": True})
|
||||
engine = RapidOCR()
|
||||
vis = VisRes()
|
||||
|
||||
image_path = "tests/test_files/ch_en_num.jpg"
|
||||
|
||||
@@ -82,7 +82,7 @@ class CTCLabelDecode:
|
||||
if character:
|
||||
character_list = character
|
||||
|
||||
if character_path:
|
||||
if character is None and character_path is not None:
|
||||
character_list = self.read_character_file(character_path)
|
||||
|
||||
if character_list is None:
|
||||
|
||||
@@ -24,14 +24,14 @@ EngineConfig:
|
||||
use_cuda: false
|
||||
use_dml: false
|
||||
|
||||
openvino:
|
||||
inference_num_threads: -1
|
||||
|
||||
paddlepaddle:
|
||||
cpu_math_library_num_threads: -1
|
||||
gpu_id: 0
|
||||
gpu_mem: 500
|
||||
|
||||
openvino:
|
||||
inference_num_threads: -1
|
||||
|
||||
torch:
|
||||
use_cuda: false
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
onnxruntime:
|
||||
PP-OCRv4:
|
||||
det:
|
||||
ch_PP-OCRv4_det_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/det/ch_PP-OCRv4_det_infer.onnx
|
||||
en_PP-OCRv3_det_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/det/en_PP-OCRv3_det_infer.onnx
|
||||
Multilingual_PP-OCRv3_det_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/det/Multilingual_PP-OCRv3_det_infer.onnx
|
||||
rec:
|
||||
arabic_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/arabic_PP-OCRv4_rec_infer.onnx
|
||||
ch_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/ch_PP-OCRv4_rec_infer.onnx
|
||||
chinese_cht_PP-OCRv3_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/chinese_cht_PP-OCRv3_rec_infer.onnx
|
||||
cyrillic_PP-OCRv3_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/cyrillic_PP-OCRv3_rec_infer.onnx
|
||||
devanagari_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/devanagari_PP-OCRv4_rec_infer.onnx
|
||||
en_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/en_PP-OCRv4_rec_infer.onnx
|
||||
japan_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/japan_PP-OCRv4_rec_infer.onnx
|
||||
ka_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/ka_PP-OCRv4_rec_infer.onnx
|
||||
korean_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/korean_PP-OCRv4_rec_infer.onnx
|
||||
latin_PP-OCRv3_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/latin_PP-OCRv3_rec_infer.onnx
|
||||
ta_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/ta_PP-OCRv4_rec_infer.onnx
|
||||
te_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/te_PP-OCRv4_rec_infer.onnx
|
||||
cls:
|
||||
ch_ppocr_mobile_v2.0_cls_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/cls/ch_ppocr_mobile_v2.0_cls_infer.onnx
|
||||
|
||||
openvino:
|
||||
PP-OCRv4:
|
||||
det:
|
||||
ch_PP-OCRv4_det_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/det/ch_PP-OCRv4_det_infer.onnx
|
||||
en_PP-OCRv3_det_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/det/en_PP-OCRv3_det_infer.onnx
|
||||
Multilingual_PP-OCRv3_det_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/det/Multilingual_PP-OCRv3_det_infer.onnx
|
||||
rec:
|
||||
arabic_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/arabic_PP-OCRv4_rec_infer.onnx
|
||||
ch_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/ch_PP-OCRv4_rec_infer.onnx
|
||||
chinese_cht_PP-OCRv3_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/chinese_cht_PP-OCRv3_rec_infer.onnx
|
||||
cyrillic_PP-OCRv3_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/cyrillic_PP-OCRv3_rec_infer.onnx
|
||||
devanagari_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/devanagari_PP-OCRv4_rec_infer.onnx
|
||||
en_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/en_PP-OCRv4_rec_infer.onnx
|
||||
japan_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/japan_PP-OCRv4_rec_infer.onnx
|
||||
ka_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/ka_PP-OCRv4_rec_infer.onnx
|
||||
korean_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/korean_PP-OCRv4_rec_infer.onnx
|
||||
latin_PP-OCRv3_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/latin_PP-OCRv3_rec_infer.onnx
|
||||
ta_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/ta_PP-OCRv4_rec_infer.onnx
|
||||
te_PP-OCRv4_rec_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/rec/te_PP-OCRv4_rec_infer.onnx
|
||||
cls:
|
||||
ch_ppocr_mobile_v2.0_cls_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/cls/ch_ppocr_mobile_v2.0_cls_infer.onnx
|
||||
|
||||
paddlepaddle:
|
||||
PP-OCRv4:
|
||||
det:
|
||||
ch_PP-OCRv4_det_infer: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/det/ch_PP-OCRv4_det_infer
|
||||
en_PP-OCRv3_det_infer: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/det/en_PP-OCRv3_det_infer
|
||||
Multilingual_PP-OCRv3_det_infer: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/det/Multilingual_PP-OCRv3_det_infer
|
||||
rec:
|
||||
arabic_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/arabic_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/arabic_PP-OCRv4_rec_infer/arabic_dict.txt
|
||||
|
||||
ch_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/ch_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/ch_PP-OCRv4_rec_infer/ppocr_keys_v1.txt
|
||||
|
||||
chinese_cht_PP-OCRv3_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/chinese_cht_PP-OCRv3_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/chinese_cht_PP-OCRv3_rec_infer/chinese_cht_dict.txt
|
||||
cyrillic_PP-OCRv3_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/cyrillic_PP-OCRv3_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/cyrillic_PP-OCRv3_rec_infer/cyrillic_dict.txt
|
||||
devanagari_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/devanagari_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/devanagari_PP-OCRv4_rec_infer/devanagari_dict.txt
|
||||
en_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/en_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/en_PP-OCRv4_rec_infer/en_dict.txt
|
||||
japan_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/japan_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/japan_PP-OCRv4_rec_infer/japan_dict.txt
|
||||
ka_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/kannada_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/kannada_PP-OCRv4_rec_infer/ka_dict.txt
|
||||
korean_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/korean_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/korean_PP-OCRv4_rec_infer/korean_dict.txt
|
||||
latin_PP-OCRv3_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/latin_PP-OCRv3_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/latin_PP-OCRv3_rec_infer/latin_dict.txt
|
||||
ta_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/ta_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/ta_PP-OCRv4_rec_infer/ta_dict.txt
|
||||
te_PP-OCRv4_rec_infer:
|
||||
model_dir: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/te_PP-OCRv4_rec_infer
|
||||
dict_url: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/paddle/PP-OCRv4/rec/te_PP-OCRv4_rec_infer/te_dict.txt
|
||||
cls:
|
||||
ch_ppocr_mobile_v2.0_cls_infer.onnx: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/onnx/PP-OCRv4/cls/ch_ppocr_mobile_v2.0_cls_infer.onnx
|
||||
|
||||
torch:
|
||||
PP-OCRv4:
|
||||
det:
|
||||
ch_PP-OCRv4_det_infer.pth: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/torch/ch_PP-OCRv4_det_infer.pth
|
||||
ch_PP-OCRv4_det_server_infer.pth: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/torch/ch_PP-OCRv4_det_server_infer.pth
|
||||
rec:
|
||||
ch_PP-OCRv4_rec_infer.pth: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/torch/ch_PP-OCRv4_rec_infer.pth
|
||||
ch_PP-OCRv4_rec_server_infer.pth: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/torch/ch_PP-OCRv4_rec_server_infer.pth
|
||||
cls:
|
||||
ch_ptocr_mobile_v2.0_cls_infer.pth: https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/torch/ch_ptocr_mobile_v2.0_cls_infer.pth
|
||||
@@ -6,9 +6,18 @@ from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import numpy as np
|
||||
import requests
|
||||
from omegaconf import OmegaConf
|
||||
from tqdm import tqdm
|
||||
|
||||
cur_dir = Path(__file__).resolve().parent
|
||||
MODEL_URL_PATH = cur_dir / "MODEL_URL.yaml"
|
||||
|
||||
|
||||
class InferSession(abc.ABC):
|
||||
model_info = OmegaConf.load(MODEL_URL_PATH)
|
||||
DEFAULT_MODE_PATH = cur_dir.parent / "models"
|
||||
|
||||
@abc.abstractmethod
|
||||
def __init__(self, config):
|
||||
pass
|
||||
@@ -18,17 +27,49 @@ class InferSession(abc.ABC):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _verify_model(model_path: Union[str, Path, None]):
|
||||
def _verify_model(model_path: Union[str, Path, None]) -> bool:
|
||||
if model_path is None:
|
||||
raise ValueError("model_path is None!")
|
||||
return False
|
||||
|
||||
model_path = Path(model_path)
|
||||
if not model_path.exists():
|
||||
raise FileNotFoundError(f"{model_path} does not exists.")
|
||||
return False
|
||||
|
||||
if not model_path.is_file():
|
||||
raise FileExistsError(f"{model_path} is not a file.")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@abc.abstractmethod
|
||||
def have_key(self, key: str = "character") -> bool:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def download_file(url: str, save_path: Union[str, Path]):
|
||||
print(f"Downloading model from {url} to {save_path}")
|
||||
response = requests.get(url, stream=True, timeout=60)
|
||||
status_code = response.status_code
|
||||
|
||||
if status_code != 200:
|
||||
raise DownloadFileError("Something went wrong while downloading models")
|
||||
|
||||
total_size_in_bytes = int(response.headers.get("content-length", 1))
|
||||
block_size = 1024 # 1 Kibibyte
|
||||
with tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True) as pb:
|
||||
with open(save_path, "wb") as file:
|
||||
for data in response.iter_content(block_size):
|
||||
pb.update(len(data))
|
||||
file.write(data)
|
||||
|
||||
@classmethod
|
||||
def get_model_url(cls, engine_name: str, task_type: str, lang: str) -> str:
|
||||
model_dict = cls.model_info[engine_name]["PP-OCRv4"][task_type]
|
||||
for k in model_dict:
|
||||
prefix = k.split("_")[0]
|
||||
if lang == prefix:
|
||||
return model_dict[k]
|
||||
raise KeyError("Model not found")
|
||||
|
||||
|
||||
class DownloadFileError(Exception):
|
||||
pass
|
||||
@@ -5,6 +5,7 @@ import os
|
||||
import platform
|
||||
import traceback
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
import numpy as np
|
||||
@@ -31,7 +32,15 @@ class OrtInferSession(InferSession):
|
||||
self.logger = get_logger("OrtInferSession")
|
||||
|
||||
model_path = config.get("model_path", None)
|
||||
self._verify_model(model_path)
|
||||
if not self._verify_model(model_path):
|
||||
self.logger.warning(
|
||||
"Model path is invalid, try to download the default model."
|
||||
)
|
||||
default_model_url = self.get_model_url(
|
||||
config.engine_name, config.task_type, config.lang
|
||||
)
|
||||
model_path = self.DEFAULT_MODE_PATH / Path(default_model_url).name
|
||||
self.download_file(default_model_url, model_path)
|
||||
|
||||
self.cfg_use_cuda = config.engine_cfg.get("use_cuda", None)
|
||||
self.cfg_use_dml = config.engine_cfg.get("use_dml", None)
|
||||
|
||||
@@ -57,17 +57,20 @@ class RapidOCR:
|
||||
config.Det.lang = det_lang
|
||||
config.Det.engine_name = engine_name
|
||||
config.Det.engine_cfg = config.EngineConfig[engine_name]
|
||||
config.Det.task_type = "det"
|
||||
self.text_det = TextDetector(config.Det)
|
||||
|
||||
self.use_cls = config.Global.use_cls
|
||||
config.Cls.engine_name = engine_name
|
||||
config.Cls.engine_cfg = config.EngineConfig[engine_name]
|
||||
config.Cls.task_type = "cls"
|
||||
self.text_cls = TextClassifier(config.Cls)
|
||||
|
||||
self.use_rec = config.Global.use_rec
|
||||
config.Rec.lang = rec_lang
|
||||
config.Rec.engine_name = engine_name
|
||||
config.Rec.engine_cfg = config.EngineConfig[engine_name]
|
||||
config.Rec.task_type = "rec"
|
||||
self.text_rec = TextRecognizer(config.Rec)
|
||||
|
||||
self.load_img = LoadImage()
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,5 +6,4 @@ from .logger import get_logger
|
||||
from .parse_parameters import ParseParams, init_args, parse_lang
|
||||
from .process_img import add_round_letterbox, increase_min_side, reduce_max_side
|
||||
from .typings import RapidOCROutput
|
||||
from .utils import download_file
|
||||
from .vis_res import VisRes
|
||||
Whitespace-only changes.
@@ -106,7 +106,7 @@ def parse_lang(lang):
|
||||
elif lang in ["en", "latin"]:
|
||||
det_lang = "en"
|
||||
else:
|
||||
det_lang = "ml"
|
||||
det_lang = "Multilingual"
|
||||
|
||||
return det_lang, lang
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# @Author: SWHL
|
||||
# @Contact: liekkaskono@163.com
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
def download_file(url: str, save_path: Union[str, Path]):
|
||||
response = requests.get(url, stream=True, timeout=60)
|
||||
status_code = response.status_code
|
||||
|
||||
if status_code != 200:
|
||||
raise DownloadFileError("Something went wrong while downloading models")
|
||||
|
||||
total_size_in_bytes = int(response.headers.get("content-length", 1))
|
||||
block_size = 1024 # 1 Kibibyte
|
||||
with tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True) as pb:
|
||||
with open(save_path, "wb") as file:
|
||||
for data in response.iter_content(block_size):
|
||||
pb.update(len(data))
|
||||
file.write(data)
|
||||
|
||||
|
||||
class DownloadFileError(Exception):
|
||||
pass
|
||||
+16
-40
@@ -14,35 +14,35 @@ root_dir = Path(__file__).resolve().parent.parent
|
||||
sys.path.append(str(root_dir))
|
||||
|
||||
from rapidocr import LoadImageError, RapidOCR
|
||||
from rapidocr.utils import download_file
|
||||
from rapidocr.inference_engine.base import InferSession
|
||||
|
||||
engine = RapidOCR()
|
||||
tests_dir = root_dir / "tests" / "test_files"
|
||||
img_path = tests_dir / "ch_en_num.jpg"
|
||||
|
||||
|
||||
def test_engine_openvino():
|
||||
engine = RapidOCR(params={"Global.with_openvino": True})
|
||||
result = engine(img_path)
|
||||
assert result.txts[0] == "正品促销"
|
||||
# def test_engine_openvino():
|
||||
# engine = RapidOCR(params={"Global.with_openvino": True})
|
||||
# result = engine(img_path)
|
||||
# assert result.txts[0] == "正品促销"
|
||||
|
||||
|
||||
def test_engine_paddle():
|
||||
engine = RapidOCR(
|
||||
params={
|
||||
"Global.with_paddle": True,
|
||||
"Det.model_path": "tests/test_files/ch_ppocr_server_v2.0_det_infer.onnx",
|
||||
"Rec.model_path": "tests/test_files/ch_ppocr_server_v2.0_rec_infer.onnx",
|
||||
}
|
||||
)
|
||||
result = engine(img_path)
|
||||
assert result.txts[0] == "正品促销"
|
||||
# def test_engine_paddle():
|
||||
# engine = RapidOCR(
|
||||
# params={
|
||||
# "Global.with_paddle": True,
|
||||
# "Det.model_path": "tests/test_files/ch_ppocr_server_v2.0_det_infer.onnx",
|
||||
# "Rec.model_path": "tests/test_files/ch_ppocr_server_v2.0_rec_infer.onnx",
|
||||
# }
|
||||
# )
|
||||
# result = engine(img_path)
|
||||
# assert result.txts[0] == "正品促销"
|
||||
|
||||
|
||||
def test_long_img():
|
||||
img_url = "https://github.com/RapidAI/RapidOCR/releases/download/v1.1.0/long.jpeg"
|
||||
img_path = tests_dir / "long.jpeg"
|
||||
download_file(img_url, save_path=img_path)
|
||||
InferSession.download_file(img_url, save_path=img_path)
|
||||
result = engine(img_path)
|
||||
|
||||
assert result is not None
|
||||
@@ -198,30 +198,6 @@ def test_input_parameters():
|
||||
assert result.boxes is None
|
||||
|
||||
|
||||
def test_input_det_parameters():
|
||||
with pytest.raises(FileNotFoundError) as exc_info:
|
||||
engine = RapidOCR(params={"Det.model_path": "1.onnx"})
|
||||
result = engine(img_path)
|
||||
raise FileNotFoundError()
|
||||
assert exc_info.type is FileNotFoundError
|
||||
|
||||
|
||||
def test_input_cls_parameters():
|
||||
with pytest.raises(FileNotFoundError) as exc_info:
|
||||
engine = RapidOCR(params={"Cls.model_path": "1.onnx"})
|
||||
result = engine(img_path)
|
||||
raise FileNotFoundError()
|
||||
assert exc_info.type is FileNotFoundError
|
||||
|
||||
|
||||
def test_input_rec_parameters():
|
||||
with pytest.raises(FileNotFoundError) as exc_info:
|
||||
engine = RapidOCR(params={"Rec.model_path": "1.onnx"})
|
||||
result = engine(img_path)
|
||||
raise FileNotFoundError()
|
||||
assert exc_info.type is FileNotFoundError
|
||||
|
||||
|
||||
def test_input_three_ndim_two_channel():
|
||||
img_npy = tests_dir / "two_dim_image.npy"
|
||||
image_array = np.load(str(img_npy))
|
||||
|
||||
Reference in new issue
Block a user