1 Star 0 Fork 7

罗浩楠/LaTeX_OCR_PRO

forked from 大漠/LaTeX_OCR_PRO 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
evaluate_txt.py 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
ジ兮尘 提交于 2019-07-20 17:09 . init
import click
from model.utils.data_generator import DataGenerator
from model.img2seq import Img2SeqModel
from model.utils.general import Config
from model.utils.text import Vocab
from model.utils.image import greyscale
from model.utils.text import load_formulas
from model.evaluation.text import score_files
@click.command()
@click.option('--results', default="results/small/", help='Dir to results')
def main(results):
# restore config and model
dir_output = results
config_data = Config(dir_output + "data.json")
config_vocab = Config(dir_output + "vocab.json")
config_model = Config(dir_output + "model.json")
vocab = Vocab(config_vocab)
model = Img2SeqModel(config_model, dir_output, vocab)
model.build_pred()
# model.restore_session(dir_output + "model_weights/")
# load dataset
test_set = DataGenerator(path_formulas=config_data.path_formulas_test,
dir_images=config_data.dir_images_test,
img_prepro=greyscale,
max_iter=config_data.max_iter,
bucket=config_data.bucket_test,
path_matching=config_data.path_matching_test,
max_len=config_data.max_length_formula,
form_prepro=vocab.form_prepro,)
# use model to write predictions in files
config_eval = Config({
"dir_answers": dir_output + "formulas_test/",
"batch_size": 20
})
files, perplexity = model.write_prediction(config_eval, test_set)
scores = score_files(files[0], files[1])
scores["perplexity"] = perplexity
msg = " || ".join(["{} is {:04.2f}".format(k, v) for k, v in scores.items()])
model.logger.info("- Test Txt: {}".format(msg))
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/haonan-online/LaTeX_OCR_PRO.git
git@gitee.com:haonan-online/LaTeX_OCR_PRO.git
haonan-online
LaTeX_OCR_PRO
LaTeX_OCR_PRO
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385