2024-02-11 08:06:50 +00:00
|
|
|
import os
|
|
|
|
|
import argparse
|
2024-04-05 07:25:06 +00:00
|
|
|
import cv2 as cv
|
2024-02-11 08:06:50 +00:00
|
|
|
|
|
|
|
|
from pathlib import Path
|
2024-04-05 07:25:06 +00:00
|
|
|
from models.ocr_model.utils.inference import inference as latex_inference
|
2024-02-11 08:06:50 +00:00
|
|
|
from models.ocr_model.model.TexTeller import TexTeller
|
2024-04-05 07:25:06 +00:00
|
|
|
from utils import load_det_tex_model, load_lang_models
|
2024-02-11 08:06:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
os.chdir(Path(__file__).resolve().parent)
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'-img',
|
|
|
|
|
type=str,
|
|
|
|
|
required=True,
|
|
|
|
|
help='path to the input image'
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'-cuda',
|
|
|
|
|
default=False,
|
|
|
|
|
action='store_true',
|
|
|
|
|
help='use cuda or not'
|
|
|
|
|
)
|
2024-04-05 07:25:06 +00:00
|
|
|
# ================= new feature ==================
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'-mix',
|
|
|
|
|
type=str,
|
|
|
|
|
help='use mix mode, only Chinese and English are supported.'
|
|
|
|
|
)
|
|
|
|
|
# ==================================================
|
2024-02-11 08:06:50 +00:00
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
# You can use your own checkpoint and tokenizer path.
|
|
|
|
|
print('Loading model and tokenizer...')
|
2024-04-05 07:25:06 +00:00
|
|
|
latex_rec_model = TexTeller.from_pretrained()
|
2024-02-11 08:06:50 +00:00
|
|
|
tokenizer = TexTeller.get_tokenizer()
|
|
|
|
|
print('Model and tokenizer loaded.')
|
|
|
|
|
|
2024-04-05 07:25:06 +00:00
|
|
|
# img_path = [args.img]
|
|
|
|
|
img = cv.imread(args.img)
|
2024-02-11 08:06:50 +00:00
|
|
|
print('Inference...')
|
2024-04-05 07:25:06 +00:00
|
|
|
if not args.mix:
|
|
|
|
|
res = latex_inference(latex_rec_model, tokenizer, [img], args.cuda)
|
|
|
|
|
print(res[0])
|
|
|
|
|
else:
|
|
|
|
|
# latex_det_model = load_det_tex_model()
|
|
|
|
|
# lang_model = load_lang_models()...
|
|
|
|
|
...
|
|
|
|
|
# res: str = mix_inference(latex_det_model, latex_rec_model, lang_model, img, args.cuda)
|
|
|
|
|
# print(res)
|