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

Method __call__

examples/FasterRCNN/data.py:80–156  ·  view source on GitHub ↗
(self, roidb)

Source from the content-addressed store, hash-verified

78 ])
79
80 def __call__(self, roidb):
81 fname, boxes, klass, is_crowd = roidb["file_name"], roidb["boxes"], roidb["class"], roidb["is_crowd"]
82 assert boxes.ndim == 2 and boxes.shape[1] == 4, boxes.shape
83 boxes = np.copy(boxes)
84 im = cv2.imread(fname, cv2.IMREAD_COLOR)
85 assert im is not None, fname
86 im = im.astype("float32")
87 height, width = im.shape[:2]
88 # assume floatbox as input
89 assert boxes.dtype == np.float32, "Loader has to return float32 boxes!"
90
91 if not self.cfg.DATA.ABSOLUTE_COORD:
92 boxes[:, 0::2] *= width
93 boxes[:, 1::2] *= height
94
95 # augmentation:
96 tfms = self.aug.get_transform(im)
97 im = tfms.apply_image(im)
98 points = box_to_point4(boxes)
99 points = tfms.apply_coords(points)
100 boxes = point4_to_box(points)
101 if len(boxes):
102 assert klass.max() <= self.cfg.DATA.NUM_CATEGORY, \
103 "Invalid category {}!".format(klass.max())
104 assert np.min(np_area(boxes)) > 0, "Some boxes have zero area!"
105
106 ret = {"image": im}
107 # Add rpn data to dataflow:
108 try:
109 if self.cfg.MODE_FPN:
110 multilevel_anchor_inputs = self.get_multilevel_rpn_anchor_input(im, boxes, is_crowd)
111 for i, (anchor_labels, anchor_boxes) in enumerate(multilevel_anchor_inputs):
112 ret["anchor_labels_lvl{}".format(i + 2)] = anchor_labels
113 ret["anchor_boxes_lvl{}".format(i + 2)] = anchor_boxes
114 else:
115 ret["anchor_labels"], ret["anchor_boxes"] = self.get_rpn_anchor_input(im, boxes, is_crowd)
116
117 boxes = boxes[is_crowd == 0] # skip crowd boxes in training target
118 klass = klass[is_crowd == 0]
119 ret["gt_boxes"] = boxes
120 ret["gt_labels"] = klass
121 except MalformedData as e:
122 log_once("Input {} is filtered for training: {}".format(fname, str(e)), "warn")
123 return None
124
125 if self.cfg.MODE_MASK:
126 # augmentation will modify the polys in-place
127 segmentation = copy.deepcopy(roidb["segmentation"])
128 segmentation = [segmentation[k] for k in range(len(segmentation)) if not is_crowd[k]]
129 assert len(segmentation) == len(boxes)
130
131 # Apply augmentation on polygon coordinates.
132 # And produce one image-sized binary mask per box.
133 masks = []
134 width_height = np.asarray([width, height], dtype=np.float32)
135 gt_mask_width = int(np.ceil(im.shape[1] / 8.0) * 8) # pad to 8 in order to pack mask into bits
136
137 for polys in segmentation:

Callers

nothing calls this directly

Calls 13

get_rpn_anchor_inputMethod · 0.95
box_to_point4Function · 0.90
point4_to_boxFunction · 0.90
log_onceFunction · 0.90
polygons_to_maskFunction · 0.90
maxMethod · 0.80
formatMethod · 0.80
minMethod · 0.80
appendMethod · 0.80
get_transformMethod · 0.45
apply_imageMethod · 0.45

Tested by

no test coverage detected