Upload folder using huggingface_hub
Browse files- mmdet_code/mmdetection/mmdet/models/dense_heads/__init__.py +3 -2
- mmdet_code/mmdetection/mmdet/models/dense_heads/dala_heads.py +7 -5
- mmdet_code/mmdetection/projects/EfficientDet/README.md +13 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_8xb16-crop512-300e_coco.py +12 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb2_bifpn_8xb16-crop512-300e_coco.py +27 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb2_bifpn_dala_8xb16-crop512-300e_coco.py +16 -0
- mmdet_code/mmdetection/projects/EfficientDet/efficientdet/__init__.py +4 -2
- mmdet_code/mmdetection/projects/EfficientDet/efficientdet/efficientdet_head.py +12 -0
- mmdet_code/train_all_levir_baseline.py +19 -1
mmdet_code/mmdetection/mmdet/models/dense_heads/__init__.py
CHANGED
|
@@ -13,7 +13,8 @@ from .condinst_head import CondInstBboxHead, CondInstMaskHead
|
|
| 13 |
from .conditional_detr_head import ConditionalDETRHead
|
| 14 |
from .corner_head import CornerHead
|
| 15 |
from .dab_detr_head import DABDETRHead
|
| 16 |
-
from .dala_heads import DalaFCOSHead, DalaRetinaHead,
|
|
|
|
| 17 |
from .ddod_head import DDODHead
|
| 18 |
from .ddq_detr_head import DDQDETRHead
|
| 19 |
from .deformable_detr_head import DeformableDETRHead
|
|
@@ -70,5 +71,5 @@ __all__ = [
|
|
| 70 |
'CondInstMaskHead', 'RTMDetInsHead', 'RTMDetInsSepBNHead',
|
| 71 |
'BoxInstBboxHead', 'BoxInstMaskHead', 'ConditionalDETRHead', 'DINOHead',
|
| 72 |
'ATSSVLFusionHead', 'DABDETRHead', 'DDQDETRHead', 'GroundingDINOHead',
|
| 73 |
-
'DalaFCOSHead', 'DalaRetinaHead', 'DalaRPNHead'
|
| 74 |
]
|
|
|
|
| 13 |
from .conditional_detr_head import ConditionalDETRHead
|
| 14 |
from .corner_head import CornerHead
|
| 15 |
from .dab_detr_head import DABDETRHead
|
| 16 |
+
from .dala_heads import (DalaAnchorTargetMixin, DalaFCOSHead, DalaRetinaHead,
|
| 17 |
+
DalaRPNHead)
|
| 18 |
from .ddod_head import DDODHead
|
| 19 |
from .ddq_detr_head import DDQDETRHead
|
| 20 |
from .deformable_detr_head import DeformableDETRHead
|
|
|
|
| 71 |
'CondInstMaskHead', 'RTMDetInsHead', 'RTMDetInsSepBNHead',
|
| 72 |
'BoxInstBboxHead', 'BoxInstMaskHead', 'ConditionalDETRHead', 'DINOHead',
|
| 73 |
'ATSSVLFusionHead', 'DABDETRHead', 'DDQDETRHead', 'GroundingDINOHead',
|
| 74 |
+
'DalaAnchorTargetMixin', 'DalaFCOSHead', 'DalaRetinaHead', 'DalaRPNHead'
|
| 75 |
]
|
mmdet_code/mmdetection/mmdet/models/dense_heads/dala_heads.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# Copyright (c) OpenMMLab. All rights reserved.
|
| 2 |
-
"""Opt-in DALA heads
|
| 3 |
|
| 4 |
from typing import Dict, List, Optional, Tuple, Union
|
| 5 |
|
|
@@ -25,7 +25,7 @@ def _dwl_gt_weights(gt_bboxes: Tensor) -> Tensor:
|
|
| 25 |
return 1 + torch.log10(torch.sqrt(areas.mean() / areas))
|
| 26 |
|
| 27 |
|
| 28 |
-
class
|
| 29 |
"""Apply DWL weights to targets returned by an anchor-based head."""
|
| 30 |
|
| 31 |
def __init__(self, use_dwl: bool = True, **kwargs) -> None:
|
|
@@ -85,12 +85,12 @@ class _DalaAnchorTargetMixin:
|
|
| 85 |
|
| 86 |
|
| 87 |
@MODELS.register_module()
|
| 88 |
-
class DalaRPNHead(
|
| 89 |
"""RPN head with optional DALA dynamic weighting loss."""
|
| 90 |
|
| 91 |
|
| 92 |
@MODELS.register_module()
|
| 93 |
-
class DalaRetinaHead(
|
| 94 |
"""RetinaNet head with optional DALA dynamic weighting loss."""
|
| 95 |
|
| 96 |
|
|
@@ -285,4 +285,6 @@ class DalaFCOSHead(FCOSHead):
|
|
| 285 |
return labels, bbox_targets, label_weights, bbox_weights
|
| 286 |
|
| 287 |
|
| 288 |
-
__all__ = [
|
|
|
|
|
|
|
|
|
| 1 |
# Copyright (c) OpenMMLab. All rights reserved.
|
| 2 |
+
"""Opt-in DALA heads and reusable target weighting utilities."""
|
| 3 |
|
| 4 |
from typing import Dict, List, Optional, Tuple, Union
|
| 5 |
|
|
|
|
| 25 |
return 1 + torch.log10(torch.sqrt(areas.mean() / areas))
|
| 26 |
|
| 27 |
|
| 28 |
+
class DalaAnchorTargetMixin:
|
| 29 |
"""Apply DWL weights to targets returned by an anchor-based head."""
|
| 30 |
|
| 31 |
def __init__(self, use_dwl: bool = True, **kwargs) -> None:
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
@MODELS.register_module()
|
| 88 |
+
class DalaRPNHead(DalaAnchorTargetMixin, RPNHead):
|
| 89 |
"""RPN head with optional DALA dynamic weighting loss."""
|
| 90 |
|
| 91 |
|
| 92 |
@MODELS.register_module()
|
| 93 |
+
class DalaRetinaHead(DalaAnchorTargetMixin, RetinaHead):
|
| 94 |
"""RetinaNet head with optional DALA dynamic weighting loss."""
|
| 95 |
|
| 96 |
|
|
|
|
| 285 |
return labels, bbox_targets, label_weights, bbox_weights
|
| 286 |
|
| 287 |
|
| 288 |
+
__all__ = [
|
| 289 |
+
'DalaAnchorTargetMixin', 'DalaFCOSHead', 'DalaRPNHead', 'DalaRetinaHead'
|
| 290 |
+
]
|
mmdet_code/mmdetection/projects/EfficientDet/README.md
CHANGED
|
@@ -58,6 +58,19 @@ python tools/test.py projects/EfficientDet/configs/tensorflow/efficientdet_effb0
|
|
| 58 |
|
| 59 |
For convenience, we recommend the current implementation version, it uses 80 categories and xyxy encoding in training. On this basis, a higher result was finally achieved.
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
### Training commands
|
| 62 |
|
| 63 |
In MMDetection's root directory, run the following command to train the model:
|
|
|
|
| 58 |
|
| 59 |
For convenience, we recommend the current implementation version, it uses 80 categories and xyxy encoding in training. On this basis, a higher result was finally achieved.
|
| 60 |
|
| 61 |
+
### Fixed-resolution D0/D2 comparison
|
| 62 |
+
|
| 63 |
+
The LEVIR benchmark runner at the repository root exposes `efficientdet_d0`
|
| 64 |
+
and `efficientdet_d2` baselines plus `dala_efficientdet_d0` and
|
| 65 |
+
`dala_efficientdet_d2` DALA variants. The DALA variants replace MaxIoU label
|
| 66 |
+
assignment with SimD/RLA and apply DWL to EfficientDet's focal classification
|
| 67 |
+
and Huber box-regression losses. All four use 512 x 512 inputs so their
|
| 68 |
+
accuracy, parameter, and FLOP results share the same input protocol. The D2
|
| 69 |
+
variant scales the backbone to EfficientNet-B2, BiFPN width/repeats to 112/5,
|
| 70 |
+
and head width to 112. Because canonical EfficientDet-D2 uses 768 x 768 inputs,
|
| 71 |
+
the fixed-512 D2 result is an architecture ablation and must not be presented
|
| 72 |
+
as a canonical EfficientDet-D2 number.
|
| 73 |
+
|
| 74 |
### Training commands
|
| 75 |
|
| 76 |
In MMDetection's root directory, run the following command to train the model:
|
mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_8xb16-crop512-300e_coco.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EfficientDet-D0 with full DALA (SimD + RLA + DWL)."""
|
| 2 |
+
|
| 3 |
+
_base_ = './efficientdet_effb0_bifpn_8xb16-crop512-300e_coco.py'
|
| 4 |
+
|
| 5 |
+
model = dict(
|
| 6 |
+
bbox_head=dict(type='DalaEfficientDetSepBNHead', use_dwl=True),
|
| 7 |
+
train_cfg=dict(
|
| 8 |
+
assigner=dict(
|
| 9 |
+
_delete_=True,
|
| 10 |
+
type='DalaAssigner',
|
| 11 |
+
ignore_iof_thr=-1,
|
| 12 |
+
sync_stats=True)))
|
mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb2_bifpn_8xb16-crop512-300e_coco.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EfficientDet-D2 architecture evaluated at a fixed 512px resolution.
|
| 2 |
+
|
| 3 |
+
The canonical D2 compound scale uses 768px inputs. This configuration keeps
|
| 4 |
+
the D0/LEVIR 512px data pipeline so D0 and D2 can be compared under the same
|
| 5 |
+
training and evaluation protocol. It therefore isolates the EfficientNet,
|
| 6 |
+
BiFPN, and prediction-head capacity increase, but its result must not be
|
| 7 |
+
reported as a canonical 768px EfficientDet-D2 result.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
_base_ = './efficientdet_effb0_bifpn_8xb16-crop512-300e_coco.py'
|
| 11 |
+
|
| 12 |
+
checkpoint = 'https://download.openmmlab.com/mmclassification/v0/efficientnet/efficientnet-b2_3rdparty_8xb32-aa-advprop_in1k_20220119-1655338a.pth' # noqa: E501
|
| 13 |
+
|
| 14 |
+
model = dict(
|
| 15 |
+
backbone=dict(
|
| 16 |
+
arch='b2',
|
| 17 |
+
drop_path_rate=0.3,
|
| 18 |
+
init_cfg=dict(
|
| 19 |
+
type='Pretrained', prefix='backbone', checkpoint=checkpoint)),
|
| 20 |
+
neck=dict(
|
| 21 |
+
num_stages=5,
|
| 22 |
+
in_channels=[48, 120, 352],
|
| 23 |
+
out_channels=112),
|
| 24 |
+
bbox_head=dict(
|
| 25 |
+
in_channels=112,
|
| 26 |
+
feat_channels=112,
|
| 27 |
+
stacked_convs=3))
|
mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb2_bifpn_dala_8xb16-crop512-300e_coco.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fixed-512 EfficientDet-D2 architecture with SimD + RLA + DWL.
|
| 2 |
+
|
| 3 |
+
This inherits the fixed-resolution D2 architecture ablation. It does not use
|
| 4 |
+
the canonical D2 input resolution of 768px.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
_base_ = './efficientdet_effb2_bifpn_8xb16-crop512-300e_coco.py'
|
| 8 |
+
|
| 9 |
+
model = dict(
|
| 10 |
+
bbox_head=dict(type='DalaEfficientDetSepBNHead', use_dwl=True),
|
| 11 |
+
train_cfg=dict(
|
| 12 |
+
assigner=dict(
|
| 13 |
+
_delete_=True,
|
| 14 |
+
type='DalaAssigner',
|
| 15 |
+
ignore_iof_thr=-1,
|
| 16 |
+
sync_stats=True)))
|
mmdet_code/mmdetection/projects/EfficientDet/efficientdet/__init__.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from .bifpn import BiFPN
|
| 2 |
from .efficientdet import EfficientDet
|
| 3 |
-
from .efficientdet_head import
|
|
|
|
| 4 |
from .huber_loss import HuberLoss
|
| 5 |
from .tensorflow.anchor_generator import YXYXAnchorGenerator
|
| 6 |
from .tensorflow.coco_90class import Coco90Dataset
|
|
@@ -11,6 +12,7 @@ from .utils import Conv2dSamePadding
|
|
| 11 |
|
| 12 |
__all__ = [
|
| 13 |
'EfficientDet', 'BiFPN', 'HuberLoss', 'EfficientDetSepBNHead',
|
| 14 |
-
'
|
|
|
|
| 15 |
'YXYXAnchorGenerator', 'TransMaxIoUAssigner', 'YXYXDeltaXYWHBBoxCoder'
|
| 16 |
]
|
|
|
|
| 1 |
from .bifpn import BiFPN
|
| 2 |
from .efficientdet import EfficientDet
|
| 3 |
+
from .efficientdet_head import (DalaEfficientDetSepBNHead,
|
| 4 |
+
EfficientDetSepBNHead)
|
| 5 |
from .huber_loss import HuberLoss
|
| 6 |
from .tensorflow.anchor_generator import YXYXAnchorGenerator
|
| 7 |
from .tensorflow.coco_90class import Coco90Dataset
|
|
|
|
| 12 |
|
| 13 |
__all__ = [
|
| 14 |
'EfficientDet', 'BiFPN', 'HuberLoss', 'EfficientDetSepBNHead',
|
| 15 |
+
'DalaEfficientDetSepBNHead', 'Conv2dSamePadding', 'Coco90Dataset',
|
| 16 |
+
'Coco90Metric',
|
| 17 |
'YXYXAnchorGenerator', 'TransMaxIoUAssigner', 'YXYXDeltaXYWHBBoxCoder'
|
| 18 |
]
|
mmdet_code/mmdetection/projects/EfficientDet/efficientdet/efficientdet_head.py
CHANGED
|
@@ -7,6 +7,7 @@ from mmcv.cnn.bricks import Swish, build_norm_layer
|
|
| 7 |
from mmengine.model import bias_init_with_prob
|
| 8 |
from torch import Tensor
|
| 9 |
|
|
|
|
| 10 |
from mmdet.models.dense_heads.anchor_head import AnchorHead
|
| 11 |
from mmdet.models.utils import images_to_levels, multi_apply
|
| 12 |
from mmdet.registry import MODELS
|
|
@@ -259,3 +260,14 @@ class EfficientDetSepBNHead(AnchorHead):
|
|
| 259 |
loss_bbox = self.loss_bbox(
|
| 260 |
bbox_pred, bbox_targets, bbox_weights, avg_factor=avg_factor * 4)
|
| 261 |
return loss_cls, loss_bbox
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from mmengine.model import bias_init_with_prob
|
| 8 |
from torch import Tensor
|
| 9 |
|
| 10 |
+
from mmdet.models.dense_heads.dala_heads import DalaAnchorTargetMixin
|
| 11 |
from mmdet.models.dense_heads.anchor_head import AnchorHead
|
| 12 |
from mmdet.models.utils import images_to_levels, multi_apply
|
| 13 |
from mmdet.registry import MODELS
|
|
|
|
| 260 |
loss_bbox = self.loss_bbox(
|
| 261 |
bbox_pred, bbox_targets, bbox_weights, avg_factor=avg_factor * 4)
|
| 262 |
return loss_cls, loss_bbox
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
@MODELS.register_module()
|
| 266 |
+
class DalaEfficientDetSepBNHead(DalaAnchorTargetMixin,
|
| 267 |
+
EfficientDetSepBNHead):
|
| 268 |
+
"""EfficientDet head with SimD/RLA assignment and optional DWL weights.
|
| 269 |
+
|
| 270 |
+
SimD and RLA are supplied by ``DalaAssigner`` in ``train_cfg``. This
|
| 271 |
+
subclass applies DWL to the classification and box-regression targets
|
| 272 |
+
while retaining EfficientDet's separate-BN prediction towers and losses.
|
| 273 |
+
"""
|
mmdet_code/train_all_levir_baseline.py
CHANGED
|
@@ -28,6 +28,22 @@ MODEL_CONFIGS = {
|
|
| 28 |
"dala_faster_rcnn": "configs/dala/faster-rcnn_r50_fpn_dala_1x_coco.py",
|
| 29 |
"dala_fcos": "configs/dala/fcos_r50-caffe_fpn_dala_1x_coco.py",
|
| 30 |
"dala_cascade_rcnn": "configs/dala/cascade-rcnn_r50_fpn_dala_1x_coco.py",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
SPLIT_RATIOS = {"train": 0.70, "val": 0.15, "test": 0.15}
|
| 33 |
SCENE_RE = re.compile(r"^(.*)_(-?\d+)_(-?\d+)$")
|
|
@@ -397,7 +413,9 @@ def parse_args() -> argparse.Namespace:
|
|
| 397 |
"--models",
|
| 398 |
default="atss,retinanet,faster_rcnn,fcos",
|
| 399 |
help=("Comma-separated model keys. DALA keys: dala_faster_rcnn, "
|
| 400 |
-
"dala_retinanet, dala_fcos, dala_cascade_rcnn."
|
|
|
|
|
|
|
| 401 |
)
|
| 402 |
parser.add_argument("--epochs", type=int, default=12)
|
| 403 |
parser.add_argument("--batch-size", type=int, default=4)
|
|
|
|
| 28 |
"dala_faster_rcnn": "configs/dala/faster-rcnn_r50_fpn_dala_1x_coco.py",
|
| 29 |
"dala_fcos": "configs/dala/fcos_r50-caffe_fpn_dala_1x_coco.py",
|
| 30 |
"dala_cascade_rcnn": "configs/dala/cascade-rcnn_r50_fpn_dala_1x_coco.py",
|
| 31 |
+
"efficientdet_d0": (
|
| 32 |
+
"projects/EfficientDet/configs/"
|
| 33 |
+
"efficientdet_effb0_bifpn_8xb16-crop512-300e_coco.py"
|
| 34 |
+
),
|
| 35 |
+
"efficientdet_d2": (
|
| 36 |
+
"projects/EfficientDet/configs/"
|
| 37 |
+
"efficientdet_effb2_bifpn_8xb16-crop512-300e_coco.py"
|
| 38 |
+
),
|
| 39 |
+
"dala_efficientdet_d0": (
|
| 40 |
+
"projects/EfficientDet/configs/"
|
| 41 |
+
"efficientdet_effb0_bifpn_dala_8xb16-crop512-300e_coco.py"
|
| 42 |
+
),
|
| 43 |
+
"dala_efficientdet_d2": (
|
| 44 |
+
"projects/EfficientDet/configs/"
|
| 45 |
+
"efficientdet_effb2_bifpn_dala_8xb16-crop512-300e_coco.py"
|
| 46 |
+
),
|
| 47 |
}
|
| 48 |
SPLIT_RATIOS = {"train": 0.70, "val": 0.15, "test": 0.15}
|
| 49 |
SCENE_RE = re.compile(r"^(.*)_(-?\d+)_(-?\d+)$")
|
|
|
|
| 413 |
"--models",
|
| 414 |
default="atss,retinanet,faster_rcnn,fcos",
|
| 415 |
help=("Comma-separated model keys. DALA keys: dala_faster_rcnn, "
|
| 416 |
+
"dala_retinanet, dala_fcos, dala_cascade_rcnn. EfficientDet "
|
| 417 |
+
"keys: efficientdet_d0, efficientdet_d2, "
|
| 418 |
+
"dala_efficientdet_d0, dala_efficientdet_d2."),
|
| 419 |
)
|
| 420 |
parser.add_argument("--epochs", type=int, default=12)
|
| 421 |
parser.add_argument("--batch-size", type=int, default=4)
|