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

Function prepare_roidb

lib/roi_data_layer/roidb.py:14–38  ·  view source on GitHub ↗

Enrich the imdb's roidb by adding some derived quantities that are useful for training. This function precomputes the maximum overlap, taken over ground-truth boxes, between each ROI and each ground-truth box. The class with maximum overlap is also recorded.

(imdb)

Source from the content-addressed store, hash-verified

12import utils.cython_bbox
13
14def prepare_roidb(imdb):
15 """Enrich the imdb's roidb by adding some derived quantities that
16 are useful for training. This function precomputes the maximum
17 overlap, taken over ground-truth boxes, between each ROI and
18 each ground-truth box. The class with maximum overlap is also
19 recorded.
20 """
21 roidb = imdb.roidb
22 for i in xrange(len(imdb.image_index)):
23 roidb[i]['image'] = imdb.image_path_at(i)
24 # need gt_overlaps as a dense array for argmax
25 gt_overlaps = roidb[i]['gt_overlaps'].toarray()
26 # max overlap with gt over classes (columns)
27 max_overlaps = gt_overlaps.max(axis=1)
28 # gt class that had the max overlap
29 max_classes = gt_overlaps.argmax(axis=1)
30 roidb[i]['max_classes'] = max_classes
31 roidb[i]['max_overlaps'] = max_overlaps
32 # sanity checks
33 # max overlap of 0 => class should be zero (background)
34 zero_inds = np.where(max_overlaps == 0)[0]
35 assert all(max_classes[zero_inds] == 0)
36 # max overlap > 0 => class should not be zero (must be a fg class)
37 nonzero_inds = np.where(max_overlaps > 0)[0]
38 assert all(max_classes[nonzero_inds] != 0)
39
40def add_bbox_regression_targets(roidb):
41 """Add information needed to train bounding-box regressors."""

Callers

nothing calls this directly

Calls 1

image_path_atMethod · 0.45

Tested by

no test coverage detected