MCPcopy
hub / github.com/rbgirshick/fast-rcnn / demo

Function demo

tools/demo.py:74–110  ·  view source on GitHub ↗

Detect object classes in an image using pre-computed object proposals.

(net, image_name, classes)

Source from the content-addressed store, hash-verified

72 plt.draw()
73
74def demo(net, image_name, classes):
75 """Detect object classes in an image using pre-computed object proposals."""
76
77 # Load pre-computed Selected Search object proposals
78 box_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo',
79 image_name + '_boxes.mat')
80 obj_proposals = sio.loadmat(box_file)['boxes']
81
82 # Load the demo image
83 im_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo', image_name + '.jpg')
84 im = cv2.imread(im_file)
85
86 # Detect all object classes and regress object bounds
87 timer = Timer()
88 timer.tic()
89 scores, boxes = im_detect(net, im, obj_proposals)
90 timer.toc()
91 print ('Detection took {:.3f}s for '
92 '{:d} object proposals').format(timer.total_time, boxes.shape[0])
93
94 # Visualize detections for each class
95 CONF_THRESH = 0.8
96 NMS_THRESH = 0.3
97 for cls in classes:
98 cls_ind = CLASSES.index(cls)
99 cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)]
100 cls_scores = scores[:, cls_ind]
101 keep = np.where(cls_scores >= CONF_THRESH)[0]
102 cls_boxes = cls_boxes[keep, :]
103 cls_scores = cls_scores[keep]
104 dets = np.hstack((cls_boxes,
105 cls_scores[:, np.newaxis])).astype(np.float32)
106 keep = nms(dets, NMS_THRESH)
107 dets = dets[keep, :]
108 print 'All {} detections with p({} | box) >= {:.1f}'.format(cls, cls,
109 CONF_THRESH)
110 vis_detections(im, cls, dets, thresh=CONF_THRESH)
111
112def parse_args():
113 """Parse input arguments."""

Callers 1

demo.pyFile · 0.85

Calls 6

ticMethod · 0.95
tocMethod · 0.95
TimerClass · 0.90
im_detectFunction · 0.90
nmsFunction · 0.85
vis_detectionsFunction · 0.70

Tested by

no test coverage detected