2024-02-11 08:06:50 +00:00
|
|
|
import os
|
|
|
|
|
import argparse
|
2024-04-06 11:38:59 +00:00
|
|
|
import cv2 as cv
|
2024-02-11 08:06:50 +00:00
|
|
|
|
|
|
|
|
from pathlib import Path
|
2024-04-06 11:38:59 +00:00
|
|
|
from utils import to_katex
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
)
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
# You can use your own checkpoint and tokenizer path.
|
|
|
|
|
print('Loading model and tokenizer...')
|
2024-04-06 11:38:59 +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-06 11:38:59 +00:00
|
|
|
img = cv.imread(args.img)
|
2024-02-11 08:06:50 +00:00
|
|
|
print('Inference...')
|
2024-04-06 11:38:59 +00:00
|
|
|
res = latex_inference(latex_rec_model, tokenizer, [img], args.cuda)
|
|
|
|
|
res = to_katex(res[0])
|
|
|
|
|
print(res)
|