NoteOnMe博客平台搭建
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

53 linhas
1.8 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, load_formulas
  6. from model.utils.image import greyscale, build_images
  7. from model.evaluation.text import score_files
  8. from model.evaluation.image import score_dirs
  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.weights/")
  21. # load dataset
  22. test_set = DataGenerator(path_formulas=config_data.path_formulas_test,
  23. dir_images=config_data.dir_images_test, img_prepro=greyscale,
  24. max_iter=1, 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,bucket_size=1)
  28. # build images from formulas
  29. formula_ref = dir_output + "formulas_test/ref.txt"
  30. formula_hyp = dir_output + "formulas_test/hyp_0.txt"
  31. images_ref = dir_output + "images_test/ref/"
  32. images_test = dir_output + "images_test/hyp_0/"
  33. build_images(load_formulas(formula_ref), images_ref)
  34. build_images(load_formulas(formula_hyp), images_test)
  35. # score the repositories
  36. scores = score_dirs(images_ref, images_test, greyscale)
  37. msg = " - ".join(["{} {:04.2f}".format(k, v) for k, v in scores.items()])
  38. model.logger.info("- Eval Img: {}".format(msg))
  39. if __name__ == "__main__":
  40. main()