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.

compatibility.md 4.3 kB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Compatibility with Other Libraries
  2. ## Compatibility with Detectron
  3. Detectron2 addresses some legacy issues left in Detectron, as a result, their models
  4. are not compatible:
  5. running inference with the same model weights will produce different results in the two code bases.
  6. The major differences regarding inference are:
  7. - The height and width of a box with corners (x1, y1) and (x2, y2) is now computed more naturally as
  8. width = x2 - x1 and height = y2 - y1;
  9. In Detectron, a "+ 1" was added both height and width.
  10. Note that the relevant ops in Caffe2 have [adopted this change of convention](https://github.com/pytorch/pytorch/pull/20550)
  11. with an extra option.
  12. So it is still possible to run inference with a Detectron2-trained model in Caffe2.
  13. The change in height/width calculations most notably changes:
  14. - encoding/decoding in bounding box regression.
  15. - non-maximum suppression. The effect here is very negligible, though.
  16. - RPN now uses simpler anchors with fewer quantization artifacts.
  17. In Detectron, the anchors were quantized and
  18. [do not have accurate areas](https://github.com/facebookresearch/Detectron/issues/227).
  19. In Detectron2, the anchors are center-aligned to feature grid points and not quantized.
  20. - Classification layers have a different ordering of class labels.
  21. This involves any trainable parameter with shape (..., num_categories + 1, ...).
  22. In Detectron2, integer labels [0, K-1] correspond to the K = num_categories object categories
  23. and the label "K" corresponds to the special "background" category.
  24. In Detectron, label "0" means background, and labels [1, K] correspond to the K categories.
  25. - ROIAlign is implemented differently. The new implementation is [available in Caffe2](https://github.com/pytorch/pytorch/pull/23706).
  26. 1. All the ROIs are shifted by half a pixel compared to Detectron in order to create better image-feature-map alignment.
  27. See `layers/roi_align.py` for details.
  28. To enable the old behavior, use `ROIAlign(aligned=False)`, or `POOLER_TYPE=ROIAlign` instead of
  29. `ROIAlignV2` (the default).
  30. 1. The ROIs are not required to have a minimum size of 1.
  31. This will lead to tiny differences in the output, but should be negligible.
  32. - Mask inference function is different.
  33. In Detectron2, the "paste_mask" function is different and should be more accurate than in Detectron. This change
  34. can improve mask AP on COCO by ~0.5% absolute.
  35. There are some other differences in training as well, but they won't affect
  36. model-level compatibility. The major ones are:
  37. - We fixed a [bug](https://github.com/facebookresearch/Detectron/issues/459) in
  38. Detectron, by making `RPN.POST_NMS_TOPK_TRAIN` per-image, rather than per-batch.
  39. The fix may lead to a small accuracy drop for a few models (e.g. keypoint
  40. detection) and will require some parameter tuning to match the Detectron results.
  41. - For simplicity, we change the default loss in bounding box regression to L1 loss, instead of smooth L1 loss.
  42. We have observed that this tends to slightly decrease box AP50 while improving box AP for higher
  43. overlap thresholds (and leading to a slight overall improvement in box AP).
  44. - We interpret the coordinates in COCO bounding box and segmentation annotations
  45. as coordinates in range `[0, width]` or `[0, height]`, and the coordinates in
  46. COCO keypoint annotations are pixel indices in range `[0, width - 1]` or `[0, height - 1]`.
  47. We will later share more details and rationale behind the above mentioned issues
  48. about pixels, coordinates, and "+1"s.
  49. ## Compatibility with Caffe2
  50. As mentioned above, despite the incompatibilities with Detectron, the relevant
  51. ops have been implemented in Caffe2, in [PR1](https://github.com/pytorch/pytorch/pull/20550)
  52. and [PR2](https://github.com/pytorch/pytorch/pull/23706).
  53. Therefore, models trained with detectron2 can be used in Caffe2.
  54. A conversion script will be available later, for easier deployment.
  55. ## Compatibility with TensorFlow
  56. Most ops are available in TensorFlow, although some tiny differences in
  57. the implementation of resize / ROIAlign / padding need to be addressed.
  58. A working conversion script is provided by [tensorpack FasterRCNN](https://github.com/tensorpack/tensorpack/tree/master/examples/FasterRCNN/convert_d2)
  59. to run a standard Detectron2 model in TensorFlow.

No Description