You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conventions.md 3.2 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Conventions
  2. Please check the following conventions if you would like to modify MMDetection as your own project.
  3. ## Loss
  4. In MMDetection, a `dict` containing losses and metrics will be returned by `model(**data)`.
  5. For example, in bbox head,
  6. ```python
  7. class BBoxHead(nn.Module):
  8. ...
  9. def loss(self, ...):
  10. losses = dict()
  11. # classification loss
  12. losses['loss_cls'] = self.loss_cls(...)
  13. # classification accuracy
  14. losses['acc'] = accuracy(...)
  15. # bbox regression loss
  16. losses['loss_bbox'] = self.loss_bbox(...)
  17. return losses
  18. ```
  19. `bbox_head.loss()` will be called during model forward.
  20. The returned dict contains `'loss_bbox'`, `'loss_cls'`, `'acc'` .
  21. Only `'loss_bbox'`, `'loss_cls'` will be used during back propagation,
  22. `'acc'` will only be used as a metric to monitor training process.
  23. By default, only values whose keys contain `'loss'` will be back propagated.
  24. This behavior could be changed by modifying `BaseDetector.train_step()`.
  25. ## Empty Proposals
  26. In MMDetection, We have added special handling and unit test for empty proposals of two-stage. We need to deal with the empty proposals of the entire batch and single image at the same time. For example, in CascadeRoIHead,
  27. ```python
  28. # simple_test method
  29. ...
  30. # There is no proposal in the whole batch
  31. if rois.shape[0] == 0:
  32. bbox_results = [[
  33. np.zeros((0, 5), dtype=np.float32)
  34. for _ in range(self.bbox_head[-1].num_classes)
  35. ]] * num_imgs
  36. if self.with_mask:
  37. mask_classes = self.mask_head[-1].num_classes
  38. segm_results = [[[] for _ in range(mask_classes)]
  39. for _ in range(num_imgs)]
  40. results = list(zip(bbox_results, segm_results))
  41. else:
  42. results = bbox_results
  43. return results
  44. ...
  45. # There is no proposal in the single image
  46. for i in range(self.num_stages):
  47. ...
  48. if i < self.num_stages - 1:
  49. for j in range(num_imgs):
  50. # Handle empty proposal
  51. if rois[j].shape[0] > 0:
  52. bbox_label = cls_score[j][:, :-1].argmax(dim=1)
  53. refine_roi = self.bbox_head[i].regress_by_class(
  54. rois[j], bbox_label, bbox_pred[j], img_metas[j])
  55. refine_roi_list.append(refine_roi)
  56. ```
  57. If you have customized `RoIHead`, you can refer to the above method to deal with empty proposals.
  58. ## Coco Panoptic Dataset
  59. In MMDetection, we have supported COCO Panoptic dataset. We clarify a few conventions about the implementation of `CocoPanopticDataset` here.
  60. 1. For mmdet<=2.16.0, the range of foreground and background labels in semantic segmentation are different from the default setting of MMDetection. The label `0` stands for `VOID` label and the category labels start from `1`.
  61. Since mmdet=2.17.0, the category labels of semantic segmentation start from `0` and label `255` stands for `VOID` for consistency with labels of bounding boxes.
  62. To achieve that, the `Pad` pipeline supports setting the padding value for `seg`.
  63. 2. In the evaluation, the panoptic result is a map with the same shape as the original image. Each value in the result map has the format of `instance_id * INSTANCE_OFFSET + category_id`.

No Description

Contributors (3)