def non_interactive_demo(model, args): renderer = create_renderer() show_window = not args.no_show for rec in tqdm(model.images_list): log.info("Starting inference for %s", rec['img_name']) image = rec['img'] distribution, targets = model.infer_sync(image) prob = calculate_probability(distribution) log.info("Confidence score is %s", prob) if prob >= args.conf_thresh ** len(distribution): phrase = model.vocab.construct_phrase(targets) if args.output_file: with open(args.output_file, 'a') as output_file: output_file.write(rec['img_name'] + '\t' + phrase + '\n') else: print("\n\tImage name: {}\n\tFormula: {}\n".format(rec['img_name'], phrase)) if renderer is not None: rendered_formula, _ = renderer.render(phrase) if rendered_formula is not None and show_window: cv.imshow("Predicted formula", rendered_formula) cv.waitKey(0) else: log.info("Confidence score is low. The formula was not recognized.") if args.perf_counts: log.info("Encoder performance statistics") print_stats(model.exec_net_encoder) log.info("Decoder performance statistics") print_stats(model.exec_net_decoder)
def __init__(self, input_model_shape, resolution): self.resolution = resolution self._tgt_shape = input_model_shape self.start_point, self.end_point = self._create_input_window() self._prev_rendered_formula = None self._prev_formula_img = None self._latex_h = 0 self._renderer = create_renderer()
def non_interactive_demo(model, args): renderer = create_renderer() show_window = not args.no_show for rec in tqdm(model.images_list): image = rec.img distribution, targets = model.infer_sync(image) prob = calculate_probability(distribution) log.info("Confidence score is {}".format(prob)) if prob >= args.conf_thresh**len(distribution): phrase = model.vocab.construct_phrase(targets) if args.output_file: with open(args.output_file, 'a') as output_file: output_file.write(rec.img_name + '\t' + phrase + '\n') else: print("\n\tImage name: {}\n\tFormula: {}\n".format( rec.img_name, phrase)) if renderer is not None: rendered_formula, _ = renderer.render(phrase) if rendered_formula is not None and show_window: cv.imshow("Predicted formula", rendered_formula) cv.waitKey(0) else: log.info( "Confidence score is low. The formula was not recognized.")