def gen_rect_image(): # Generator for yielding (rect,cropped) tuples image = np.array(Image.open(image_file).convert(mode='RGB')) rects = data_tools.parse_boxes_from_text(rects_file,slice_first=True)[0] for rect in rects: cropped = data_tools.normalize_box(image,rect,**kwargs) yield rect, cropped
def gen_rect_image(): # Generator for yielding (rect,cropped) tuples image = cv2.imread(image_file)[:, :, ::-1] # BGR->RGB rects = data_tools.parse_boxes_from_text(rects_file, slice_first=True)[0] for rect in rects: cropped = data_tools.normalize_box(image, rect, **kwargs) yield rect, cropped
def main(argv=None): """Loads up ground truth and prediction files, calculates and prints statistics """ # Load file lists prediction_files = data_tools.get_filenames( FLAGS.pred_path, str.split(FLAGS.filename_pattern,','), 'txt') ground_truth_files = data_tools.get_paired_filenames( prediction_files, FLAGS.gt_path, 'json' ) assert len(ground_truth_files) == len(prediction_files) # Load files contents and package for stats evaluation predictions = {} ground_truths = {} for pred_file,truth_file in zip(prediction_files,ground_truth_files): base = os.path.splitext(os.path.basename(pred_file))[0] [_,gt_polys,gt_labels] = data_tools.parse_boxes_from_json( truth_file ) [_,polys,labels,scores] = data_tools.parse_boxes_from_text( pred_file ) if FLAGS.score_thresh: # Filter predictions if necessary polys,labels,scores = threshold_predictions( polys, labels, scores) predictions[base] = { 'polygons' : polys, 'labels' : labels, 'scores' : scores } ground_truths[base] = {'polygons' : gt_polys, 'labels' : gt_labels } # Calculate statistics on predictions for ground truths sample_stats,total_stats = stats.evaluate_predictions( ground_truths, predictions, match_labels=FLAGS.match_labels, iou_match_thresh=FLAGS.iou_thresh) # Display save the results print sample_stats print total_stats if FLAGS.save_result: import json with open(os.path.join(FLAGS.pred_path,FLAGS.save_result+'.json'),'w') \ as fd: json.dump({'individual': sample_stats, 'overall': total_stats}, fd, indent=4)