NoteOnMe博客平台搭建
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

51 строка
1.7 KiB

  1. import click
  2. from model.utils.data_generator import DataGenerator
  3. from model.img2seq import Img2SeqModel
  4. from model.utils.general import Config
  5. from model.utils.text import Vocab
  6. from model.utils.image import greyscale
  7. from model.utils.text import load_formulas
  8. from model.evaluation.text import score_files
  9. @click.command()
  10. @click.option('--results', default="results/full/", help='Dir to results')
  11. def main(results):
  12. # restore config and model
  13. dir_output = results
  14. config_data = Config(dir_output + "data.json")
  15. config_vocab = Config(dir_output + "vocab.json")
  16. config_model = Config(dir_output + "model.json")
  17. vocab = Vocab(config_vocab)
  18. model = Img2SeqModel(config_model, dir_output, vocab)
  19. model.build_pred()
  20. model.restore_session(dir_output + "model.weights4/test-model.ckpt")
  21. # load dataset
  22. test_set = DataGenerator(path_formulas=config_data.path_formulas_test,
  23. dir_images=config_data.dir_images_test,
  24. max_iter=3000, bucket=config_data.bucket_test,
  25. path_matching=config_data.path_matching_test,
  26. max_len=config_data.max_length_formula,
  27. form_prepro=vocab.form_prepro)
  28. # use model to write predictions in files
  29. config_eval = Config({"dir_answers": dir_output + "formulas_test/",
  30. "batch_size": 20})
  31. files, perplexity = model.write_prediction(config_eval, test_set)
  32. formula_ref, formula_hyp = files[0], files[1]
  33. # score the ref and prediction files
  34. scores = score_files(formula_ref, formula_hyp)
  35. scores["perplexity"] = perplexity
  36. msg = " - ".join(["{} {:04.2f}".format(k, v) for k, v in scores.items()])
  37. model.logger.info("- Test Txt: {}".format(msg))
  38. if __name__ == "__main__":
  39. main()