MCPcopy
hub / github.com/alibaba/EasyCV / _new_forward_test

Method _new_forward_test

easycv/utils/mmlab_utils.py:232–294  ·  view source on GitHub ↗
(self, img, img_metas=None, **kwargs)

Source from the content-addressed store, hash-verified

230 origin_forward_test = cls.forward_test
231
232 def _new_forward_test(self, img, img_metas=None, **kwargs):
233 kwargs.update({'rescale': True}) # move from single_gpu_test
234 logging.info('Set rescale to True for `model.forward_test`!')
235
236 result = origin_forward_test(self, img, img_metas, **kwargs)
237 # ============result process to adapt to easycv============
238 # encode mask results
239 if isinstance(result[0], tuple):
240 result = [(bbox_results, encode_mask_results(mask_results))
241 for bbox_results, mask_results in result]
242 # This logic is only used in panoptic segmentation test.
243 elif isinstance(result[0], dict) and 'ins_results' in result[0]:
244 for j in range(len(result)):
245 bbox_results, mask_results = result[j]['ins_results']
246 result[j]['ins_results'] = (
247 bbox_results, encode_mask_results(mask_results))
248
249 detection_boxes = []
250 detection_scores = []
251 detection_classes = []
252 detection_masks = []
253 for res_i in result:
254 if isinstance(res_i, tuple):
255 bbox_result, segm_result = res_i
256 if isinstance(segm_result, tuple):
257 segm_result = segm_result[0] # ms rcnn
258 else:
259 bbox_result, segm_result = res_i, None
260 bboxes = np.vstack(bbox_result)
261 labels = [
262 np.full(bbox.shape[0], i, dtype=np.int32)
263 for i, bbox in enumerate(bbox_result)
264 ]
265 labels = np.concatenate(labels)
266 # draw segmentation masks
267 segms = []
268 if segm_result is not None and len(labels) > 0: # non empty
269
270 segms = mmcv.concat_list(segm_result)
271 if isinstance(segms[0], torch.Tensor):
272 segms = torch.stack(
273 segms, dim=0).detach().cpu().numpy()
274 else:
275 segms = np.stack(segms, axis=0)
276
277 scores = bboxes[:, 4] if bboxes.shape[1] == 5 else None
278 bboxes = bboxes[:, 0:4] if bboxes.shape[1] == 5 else bboxes
279 assert bboxes.shape[1] == 4
280
281 detection_boxes.append(bboxes)
282 detection_scores.append(scores)
283 detection_classes.append(labels)
284 detection_masks.append(segms)
285
286 assert len(img_metas) == 1
287 outputs = {
288 'detection_boxes': detection_boxes,
289 'detection_scores': detection_scores,

Callers

nothing calls this directly

Calls 2

updateMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected