MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / do_visualize

Function do_visualize

examples/FasterRCNN/predict.py:29–78  ·  view source on GitHub ↗

Visualize some intermediate results (proposals, raw predictions) inside the pipeline.

(model, model_path, nr_visualize=100, output_dir='output')

Source from the content-addressed store, hash-verified

27
28
29def do_visualize(model, model_path, nr_visualize=100, output_dir='output'):
30 """
31 Visualize some intermediate results (proposals, raw predictions) inside the pipeline.
32 """
33 df = get_train_dataflow()
34 df.reset_state()
35
36 pred = OfflinePredictor(PredictConfig(
37 model=model,
38 session_init=SmartInit(model_path),
39 input_names=['image', 'gt_boxes', 'gt_labels'],
40 output_names=[
41 'generate_{}_proposals/boxes'.format('fpn' if cfg.MODE_FPN else 'rpn'),
42 'generate_{}_proposals/scores'.format('fpn' if cfg.MODE_FPN else 'rpn'),
43 'fastrcnn_all_scores',
44 'output/boxes',
45 'output/scores',
46 'output/labels',
47 ]))
48
49 if os.path.isdir(output_dir):
50 shutil.rmtree(output_dir)
51 fs.mkdir_p(output_dir)
52 with tqdm.tqdm(total=nr_visualize) as pbar:
53 for idx, dp in itertools.islice(enumerate(df), nr_visualize):
54 img, gt_boxes, gt_labels = dp['image'], dp['gt_boxes'], dp['gt_labels']
55
56 rpn_boxes, rpn_scores, all_scores, \
57 final_boxes, final_scores, final_labels = pred(img, gt_boxes, gt_labels)
58
59 # draw groundtruth boxes
60 gt_viz = draw_annotation(img, gt_boxes, gt_labels)
61 # draw best proposals for each groundtruth, to show recall
62 proposal_viz, good_proposals_ind = draw_proposal_recall(img, rpn_boxes, rpn_scores, gt_boxes)
63 # draw the scores for the above proposals
64 score_viz = draw_predictions(img, rpn_boxes[good_proposals_ind], all_scores[good_proposals_ind])
65
66 results = [DetectionResult(*args) for args in
67 zip(final_boxes, final_scores, final_labels,
68 [None] * len(final_labels))]
69 final_viz = draw_final_outputs(img, results)
70
71 viz = tpviz.stack_patches([
72 gt_viz, proposal_viz,
73 score_viz, final_viz], 2, 2)
74
75 if os.environ.get('DISPLAY', None):
76 tpviz.interactive_imshow(viz)
77 cv2.imwrite("{}/{:03d}.png".format(output_dir, idx), viz)
78 pbar.update()
79
80
81def do_evaluate(pred_config, output_file):

Callers 1

predict.pyFile · 0.85

Calls 12

get_train_dataflowFunction · 0.90
OfflinePredictorClass · 0.90
PredictConfigClass · 0.90
SmartInitFunction · 0.90
draw_annotationFunction · 0.90
draw_proposal_recallFunction · 0.90
draw_predictionsFunction · 0.90
draw_final_outputsFunction · 0.90
formatMethod · 0.80
updateMethod · 0.80
reset_stateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected