Created
November 30, 2019 00:14
-
-
Save mikewlange/24bbd0dc4b11eb87035a77fb3769f9a0 to your computer and use it in GitHub Desktop.
/AIML'/im2latex-master/evaluate_img.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"lines_to_next_cell": 2, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import click", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from model.utils.data_generator import DataGenerator\nfrom model.img2seq import Img2SeqModel\nfrom model.utils.general import Config\nfrom model.utils.text import Vocab, load_formulas\nfrom model.utils.image import greyscale, build_images", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from model.evaluation.text import score_files\nfrom model.evaluation.image import score_dirs", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"lines_to_next_cell": 2, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@click.command()\[email protected]('--results', default=\"results/small/\", help='Dir to results')\ndef main(results):\n # restore config and model\n dir_output = results\n\n config_data = Config(dir_output + \"data.json\")\n config_vocab = Config(dir_output + \"vocab.json\")\n config_model = Config(dir_output + \"model.json\")\n\n vocab = Vocab(config_vocab)\n model = Img2SeqModel(config_model, dir_output, vocab)\n model.build_pred()\n model.restore_session(dir_output + \"model.weights/\")\n\n # load dataset\n test_set = DataGenerator(path_formulas=config_data.path_formulas_test,\n dir_images=config_data.dir_images_test, img_prepro=greyscale,\n max_iter=config_data.max_iter, bucket=config_data.bucket_test,\n path_matching=config_data.path_matching_test,\n max_len=config_data.max_length_formula,\n form_prepro=vocab.form_prepro,)\n\n\n # build images from formulas\n formula_ref = dir_output + \"formulas_test/ref.txt\"\n formula_hyp = dir_output + \"formulas_test/hyp_0.txt\"\n images_ref = dir_output + \"images_test/ref/\"\n images_test = dir_output + \"images_test/hyp_0/\"\n build_images(load_formulas(formula_ref), images_ref)\n build_images(load_formulas(formula_hyp), images_test)\n\n # score the repositories\n scores = score_dirs(images_ref, images_test, greyscale)\n msg = \" - \".join([\"{} {:04.2f}\".format(k, v) for k, v in scores.items()])\n model.logger.info(\"- Eval Img: {}\".format(msg))", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "if __name__ == \"__main__\":\n main()", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"jupytext": { | |
"notebook_metadata_filter": "-all", | |
"cell_metadata_filter": "-all", | |
"text_representation": { | |
"extension": ".py", | |
"format_name": "light" | |
} | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"varInspector": { | |
"window_display": false, | |
"cols": { | |
"lenName": 16, | |
"lenType": 16, | |
"lenVar": 40 | |
}, | |
"kernels_config": { | |
"python": { | |
"library": "var_list.py", | |
"delete_cmd_prefix": "del ", | |
"delete_cmd_postfix": "", | |
"varRefreshCmd": "print(var_dic_list())" | |
}, | |
"r": { | |
"library": "var_list.r", | |
"delete_cmd_prefix": "rm(", | |
"delete_cmd_postfix": ") ", | |
"varRefreshCmd": "cat(var_dic_list()) " | |
} | |
}, | |
"types_to_exclude": [ | |
"module", | |
"function", | |
"builtin_function_or_method", | |
"instance", | |
"_Feature" | |
] | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": false, | |
"sideBar": false, | |
"skip_h1_title": false, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": false, | |
"toc_window_display": false | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.6.9", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "/AIML'/im2latex-master/evaluate_img.py", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment