|
8 | 8 |
|
9 | 9 | from detectron2.modeling import meta_arch |
10 | 10 | from detectron2.modeling.box_regression import Box2BoxTransform |
11 | | -from detectron2.modeling.meta_arch.panoptic_fpn import combine_semantic_and_instance_outputs |
12 | 11 | from detectron2.modeling.meta_arch.retinanet import permute_to_N_HWA_K |
13 | | -from detectron2.modeling.postprocessing import detector_postprocess, sem_seg_postprocess |
14 | 12 | from detectron2.modeling.roi_heads import keypoint_head |
15 | 13 | from detectron2.structures import Boxes, ImageList, Instances, RotatedBoxes |
16 | 14 |
|
@@ -285,101 +283,6 @@ def f(batched_inputs, c2_inputs, c2_results): |
285 | 283 | return f |
286 | 284 |
|
287 | 285 |
|
288 | | -class Caffe2PanopticFPN(Caffe2MetaArch): |
289 | | - def __init__(self, cfg, torch_model): |
290 | | - assert isinstance(torch_model, meta_arch.PanopticFPN) |
291 | | - torch_model = patch_generalized_rcnn(torch_model) |
292 | | - super().__init__(cfg, torch_model) |
293 | | - |
294 | | - self.roi_heads_patcher = ROIHeadsPatcher( |
295 | | - self._wrapped_model.roi_heads, cfg.EXPORT_CAFFE2.USE_HEATMAP_MAX_KEYPOINT |
296 | | - ) |
297 | | - |
298 | | - @mock_torch_nn_functional_interpolate() |
299 | | - def forward(self, inputs): |
300 | | - assert self.tensor_mode |
301 | | - images = self._caffe2_preprocess_image(inputs) |
302 | | - features = self._wrapped_model.backbone(images.tensor) |
303 | | - |
304 | | - sem_seg_results, _ = self._wrapped_model.sem_seg_head(features) |
305 | | - sem_seg_results = alias(sem_seg_results, "sem_seg") |
306 | | - |
307 | | - proposals, _ = self._wrapped_model.proposal_generator(images, features) |
308 | | - |
309 | | - with self.roi_heads_patcher.mock_roi_heads(self.tensor_mode): |
310 | | - detector_results, _ = self._wrapped_model.roi_heads(images, features, proposals) |
311 | | - |
312 | | - return tuple(detector_results[0].flatten()) + (sem_seg_results,) |
313 | | - |
314 | | - def encode_additional_info(self, predict_net, init_net): |
315 | | - size_divisibility = self._wrapped_model.backbone.size_divisibility |
316 | | - check_set_pb_arg(predict_net, "size_divisibility", "i", size_divisibility) |
317 | | - check_set_pb_arg( |
318 | | - predict_net, "device", "s", str.encode(str(self._wrapped_model.device), "ascii") |
319 | | - ) |
320 | | - check_set_pb_arg(predict_net, "meta_architecture", "s", b"PanopticFPN") |
321 | | - |
322 | | - # Inference parameters: |
323 | | - check_set_pb_arg( |
324 | | - predict_net, |
325 | | - "combine_overlap_threshold", |
326 | | - "f", |
327 | | - _cast_to_f32(self._wrapped_model.combine_overlap_thresh), |
328 | | - ) |
329 | | - check_set_pb_arg( |
330 | | - predict_net, |
331 | | - "combine_stuff_area_limit", |
332 | | - "i", |
333 | | - self._wrapped_model.combine_stuff_area_thresh, |
334 | | - ) |
335 | | - check_set_pb_arg( |
336 | | - predict_net, |
337 | | - "combine_instances_confidence_threshold", |
338 | | - "f", |
339 | | - _cast_to_f32(self._wrapped_model.combine_instances_score_thresh), |
340 | | - ) |
341 | | - |
342 | | - @staticmethod |
343 | | - def get_outputs_converter(predict_net, init_net): |
344 | | - combine_overlap_threshold = get_pb_arg_valf(predict_net, "combine_overlap_threshold", None) |
345 | | - combine_stuff_area_limit = get_pb_arg_vali(predict_net, "combine_stuff_area_limit", None) |
346 | | - combine_instances_confidence_threshold = get_pb_arg_valf( |
347 | | - predict_net, "combine_instances_confidence_threshold", None |
348 | | - ) |
349 | | - |
350 | | - def f(batched_inputs, c2_inputs, c2_results): |
351 | | - _, im_info = c2_inputs |
352 | | - image_sizes = [[int(im[0]), int(im[1])] for im in im_info] |
353 | | - detector_results = assemble_rcnn_outputs_by_name( |
354 | | - image_sizes, c2_results, force_mask_on=True |
355 | | - ) |
356 | | - sem_seg_results = c2_results["sem_seg"] |
357 | | - |
358 | | - # copied from meta_arch/panoptic_fpn.py ... |
359 | | - processed_results = [] |
360 | | - for sem_seg_result, detector_result, input_per_image, image_size in zip( |
361 | | - sem_seg_results, detector_results, batched_inputs, image_sizes |
362 | | - ): |
363 | | - height = input_per_image.get("height", image_size[0]) |
364 | | - width = input_per_image.get("width", image_size[1]) |
365 | | - sem_seg_r = sem_seg_postprocess(sem_seg_result, image_size, height, width) |
366 | | - detector_r = detector_postprocess(detector_result, height, width) |
367 | | - |
368 | | - processed_results.append({"sem_seg": sem_seg_r, "instances": detector_r}) |
369 | | - |
370 | | - panoptic_r = combine_semantic_and_instance_outputs( |
371 | | - detector_r, |
372 | | - sem_seg_r.argmax(dim=0), |
373 | | - combine_overlap_threshold, |
374 | | - combine_stuff_area_limit, |
375 | | - combine_instances_confidence_threshold, |
376 | | - ) |
377 | | - processed_results[-1]["panoptic_seg"] = panoptic_r |
378 | | - return processed_results |
379 | | - |
380 | | - return f |
381 | | - |
382 | | - |
383 | 286 | class Caffe2RetinaNet(Caffe2MetaArch): |
384 | 287 | def __init__(self, cfg, torch_model): |
385 | 288 | assert isinstance(torch_model, meta_arch.RetinaNet) |
@@ -498,6 +401,5 @@ def f(batched_inputs, c2_inputs, c2_results): |
498 | 401 |
|
499 | 402 | META_ARCH_CAFFE2_EXPORT_TYPE_MAP = { |
500 | 403 | "GeneralizedRCNN": Caffe2GeneralizedRCNN, |
501 | | - "PanopticFPN": Caffe2PanopticFPN, |
502 | 404 | "RetinaNet": Caffe2RetinaNet, |
503 | 405 | } |
0 commit comments