Upload folder using huggingface_hub
Browse files- mmdet_code/mmdetection/mmdet/models/dense_heads/__pycache__/dala_heads.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/mmdet/models/dense_heads/dala_heads.py +59 -1
- mmdet_code/mmdetection/mmdet/models/task_modules/__init__.py +3 -1
- mmdet_code/mmdetection/mmdet/models/task_modules/__pycache__/__init__.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/mmdet/models/task_modules/__pycache__/ftsc_calibrator.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/mmdet/models/task_modules/ftsc_calibrator.py +143 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/__pycache__/efficientdet_effb0_bifpn_dala_ftsc_f1_level_8xb16-crop512-100e_levir.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/__pycache__/efficientdet_effb0_bifpn_dala_ftsc_f2_quality_8xb16-crop512-100e_levir.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/__pycache__/efficientdet_effb0_bifpn_dala_ftsc_f3_level_quality_8xb16-crop512-100e_levir.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_ftsc_f1_level_8xb16-crop512-100e_levir.py +18 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_ftsc_f2_quality_8xb16-crop512-100e_levir.py +19 -0
- mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_ftsc_f3_level_quality_8xb16-crop512-100e_levir.py +19 -0
- mmdet_code/mmdetection/projects/EfficientDet/tests/__pycache__/test_dala_efficientdet_head.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/projects/EfficientDet/tests/test_dala_efficientdet_head.py +70 -0
- mmdet_code/mmdetection/tests/test_models/test_task_modules/__pycache__/test_ftsc_calibrator.cpython-313.pyc +0 -0
- mmdet_code/mmdetection/tests/test_models/test_task_modules/test_ftsc_calibrator.py +78 -0
mmdet_code/mmdetection/mmdet/models/dense_heads/__pycache__/dala_heads.cpython-313.pyc
CHANGED
|
Binary files a/mmdet_code/mmdetection/mmdet/models/dense_heads/__pycache__/dala_heads.cpython-313.pyc and b/mmdet_code/mmdetection/mmdet/models/dense_heads/__pycache__/dala_heads.cpython-313.pyc differ
|
|
|
mmdet_code/mmdetection/mmdet/models/dense_heads/dala_heads.py
CHANGED
|
@@ -11,6 +11,7 @@ from mmdet.registry import MODELS
|
|
| 11 |
from mmdet.structures.bbox import BaseBoxes, get_box_tensor
|
| 12 |
from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
|
| 13 |
from ..task_modules.assigners.dala_assigner import DalaPositiveQuota
|
|
|
|
| 14 |
from ..task_modules.prior_generators import anchor_inside_flags
|
| 15 |
from ..utils import multi_apply, unmap
|
| 16 |
from .fcos_head import FCOSHead
|
|
@@ -28,10 +29,54 @@ def _dwl_gt_weights(gt_bboxes: Tensor) -> Tensor:
|
|
| 28 |
class DalaAnchorTargetMixin:
|
| 29 |
"""Apply DWL weights to targets returned by an anchor-based head."""
|
| 30 |
|
| 31 |
-
def __init__(self,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
self.use_dwl = use_dwl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
super().__init__(**kwargs)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def get_targets(self,
|
| 36 |
anchor_list: List[List[Tensor]],
|
| 37 |
valid_flag_list: List[List[Tensor]],
|
|
@@ -141,6 +186,19 @@ class DalaAnchorTargetMixin:
|
|
| 141 |
if len(neg_inds) > 0:
|
| 142 |
label_weights[neg_inds] = negative_weight
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
if unmap_outputs:
|
| 145 |
num_total_anchors = flat_anchors.size(0)
|
| 146 |
labels = unmap(
|
|
|
|
| 11 |
from mmdet.structures.bbox import BaseBoxes, get_box_tensor
|
| 12 |
from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
|
| 13 |
from ..task_modules.assigners.dala_assigner import DalaPositiveQuota
|
| 14 |
+
from ..task_modules.ftsc_calibrator import FpnTinySupervisionCalibrator
|
| 15 |
from ..task_modules.prior_generators import anchor_inside_flags
|
| 16 |
from ..utils import multi_apply, unmap
|
| 17 |
from .fcos_head import FCOSHead
|
|
|
|
| 29 |
class DalaAnchorTargetMixin:
|
| 30 |
"""Apply DWL weights to targets returned by an anchor-based head."""
|
| 31 |
|
| 32 |
+
def __init__(self,
|
| 33 |
+
use_dwl: bool = True,
|
| 34 |
+
use_ftsc: bool = False,
|
| 35 |
+
ftsc_mode: str = 'level_quality',
|
| 36 |
+
ftsc_lambda_level: float = 1.0,
|
| 37 |
+
ftsc_alpha_level: float = 1.0,
|
| 38 |
+
ftsc_beta_quality: float = 1.0,
|
| 39 |
+
ftsc_weight_min: float = 0.25,
|
| 40 |
+
ftsc_weight_max: float = 2.0,
|
| 41 |
+
ftsc_normalize: bool = True,
|
| 42 |
+
**kwargs) -> None:
|
| 43 |
self.use_dwl = use_dwl
|
| 44 |
+
self.use_ftsc = use_ftsc
|
| 45 |
+
if ftsc_mode not in {'level', 'quality', 'level_quality'}:
|
| 46 |
+
raise ValueError(
|
| 47 |
+
'ftsc_mode must be one of level, quality, or level_quality')
|
| 48 |
+
if ftsc_lambda_level < 0:
|
| 49 |
+
raise ValueError('ftsc_lambda_level must be non-negative')
|
| 50 |
+
if ftsc_weight_min <= 0 or ftsc_weight_max <= 0:
|
| 51 |
+
raise ValueError('FTSC weight clamps must be positive')
|
| 52 |
+
if ftsc_weight_min > ftsc_weight_max:
|
| 53 |
+
raise ValueError('ftsc_weight_min must not exceed ftsc_weight_max')
|
| 54 |
+
self.ftsc_mode = ftsc_mode
|
| 55 |
+
self.ftsc_lambda_level = ftsc_lambda_level
|
| 56 |
+
self.ftsc_alpha_level = ftsc_alpha_level
|
| 57 |
+
self.ftsc_beta_quality = ftsc_beta_quality
|
| 58 |
+
self.ftsc_weight_min = ftsc_weight_min
|
| 59 |
+
self.ftsc_weight_max = ftsc_weight_max
|
| 60 |
+
self.ftsc_normalize = ftsc_normalize
|
| 61 |
+
self.ftsc_calibrator = FpnTinySupervisionCalibrator(
|
| 62 |
+
mode=ftsc_mode,
|
| 63 |
+
lambda_level=ftsc_lambda_level,
|
| 64 |
+
alpha_level=ftsc_alpha_level,
|
| 65 |
+
beta_quality=ftsc_beta_quality,
|
| 66 |
+
weight_min=ftsc_weight_min,
|
| 67 |
+
weight_max=ftsc_weight_max,
|
| 68 |
+
normalize=ftsc_normalize,
|
| 69 |
+
)
|
| 70 |
super().__init__(**kwargs)
|
| 71 |
|
| 72 |
+
@torch.no_grad()
|
| 73 |
+
def _ftsc_positive_weights(self, anchors: Tensor, level_ids: Tensor,
|
| 74 |
+
gt_bboxes: Tensor, pos_inds: Tensor,
|
| 75 |
+
pos_assigned_gt_inds: Tensor) -> Tensor:
|
| 76 |
+
"""Delegate FTSC-v1 computation to the standalone calibrator."""
|
| 77 |
+
return self.ftsc_calibrator(
|
| 78 |
+
anchors, level_ids, gt_bboxes, pos_inds, pos_assigned_gt_inds)
|
| 79 |
+
|
| 80 |
def get_targets(self,
|
| 81 |
anchor_list: List[List[Tensor]],
|
| 82 |
valid_flag_list: List[List[Tensor]],
|
|
|
|
| 186 |
if len(neg_inds) > 0:
|
| 187 |
label_weights[neg_inds] = negative_weight
|
| 188 |
|
| 189 |
+
if self.use_ftsc and len(pos_inds) > 0:
|
| 190 |
+
gt_bboxes = gt_instances.bboxes.tensor if isinstance(
|
| 191 |
+
gt_instances.bboxes, BaseBoxes) else gt_instances.bboxes
|
| 192 |
+
level_ids = getattr(pred_instances, 'level_ids', None)
|
| 193 |
+
ftsc_weights = self._ftsc_positive_weights(
|
| 194 |
+
anchors, level_ids, gt_bboxes, pos_inds,
|
| 195 |
+
sampling_result.pos_assigned_gt_inds)
|
| 196 |
+
label_weights[pos_inds] = label_weights[pos_inds] * ftsc_weights
|
| 197 |
+
bbox_weights[pos_inds] = bbox_weights[pos_inds] * ftsc_weights[:,
|
| 198 |
+
None]
|
| 199 |
+
if len(neg_inds) > 0:
|
| 200 |
+
label_weights[neg_inds] = label_weights[pos_inds].mean()
|
| 201 |
+
|
| 202 |
if unmap_outputs:
|
| 203 |
num_total_anchors = flat_anchors.size(0)
|
| 204 |
labels = unmap(
|
mmdet_code/mmdetection/mmdet/models/task_modules/__init__.py
CHANGED
|
@@ -6,6 +6,7 @@ from .builder import (ANCHOR_GENERATORS, BBOX_ASSIGNERS, BBOX_CODERS,
|
|
| 6 |
build_bbox_coder, build_iou_calculator, build_match_cost,
|
| 7 |
build_prior_generator, build_sampler)
|
| 8 |
from .coders import * # noqa: F401,F403
|
|
|
|
| 9 |
from .prior_generators import * # noqa: F401,F403
|
| 10 |
from .samplers import * # noqa: F401,F403
|
| 11 |
from .tracking import * # noqa: F401,F403
|
|
@@ -14,5 +15,6 @@ __all__ = [
|
|
| 14 |
'ANCHOR_GENERATORS', 'PRIOR_GENERATORS', 'BBOX_ASSIGNERS', 'BBOX_SAMPLERS',
|
| 15 |
'MATCH_COSTS', 'BBOX_CODERS', 'IOU_CALCULATORS', 'build_anchor_generator',
|
| 16 |
'build_prior_generator', 'build_assigner', 'build_sampler',
|
| 17 |
-
'build_iou_calculator', 'build_match_cost', 'build_bbox_coder'
|
|
|
|
| 18 |
]
|
|
|
|
| 6 |
build_bbox_coder, build_iou_calculator, build_match_cost,
|
| 7 |
build_prior_generator, build_sampler)
|
| 8 |
from .coders import * # noqa: F401,F403
|
| 9 |
+
from .ftsc_calibrator import FpnTinySupervisionCalibrator, simd_quality
|
| 10 |
from .prior_generators import * # noqa: F401,F403
|
| 11 |
from .samplers import * # noqa: F401,F403
|
| 12 |
from .tracking import * # noqa: F401,F403
|
|
|
|
| 15 |
'ANCHOR_GENERATORS', 'PRIOR_GENERATORS', 'BBOX_ASSIGNERS', 'BBOX_SAMPLERS',
|
| 16 |
'MATCH_COSTS', 'BBOX_CODERS', 'IOU_CALCULATORS', 'build_anchor_generator',
|
| 17 |
'build_prior_generator', 'build_assigner', 'build_sampler',
|
| 18 |
+
'build_iou_calculator', 'build_match_cost', 'build_bbox_coder',
|
| 19 |
+
'FpnTinySupervisionCalibrator', 'simd_quality'
|
| 20 |
]
|
mmdet_code/mmdetection/mmdet/models/task_modules/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (898 Bytes). View file
|
|
|
mmdet_code/mmdetection/mmdet/models/task_modules/__pycache__/ftsc_calibrator.cpython-313.pyc
ADDED
|
Binary file (9.17 kB). View file
|
|
|
mmdet_code/mmdetection/mmdet/models/task_modules/ftsc_calibrator.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) OpenMMLab. All rights reserved.
|
| 2 |
+
"""FPN-aware Tiny-object Supervision Calibration (FTSC).
|
| 3 |
+
|
| 4 |
+
FTSC is intentionally independent from DALA assignment. It is a training-only
|
| 5 |
+
post-assignment loss-weight calibrator: given already assigned positives, it
|
| 6 |
+
computes how strongly each positive should contribute to classification and
|
| 7 |
+
box-regression loss.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import torch
|
| 13 |
+
from torch import Tensor
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def simd_quality(priors: Tensor,
|
| 17 |
+
gt_bboxes: Tensor,
|
| 18 |
+
eps: float = 1e-7) -> Tensor:
|
| 19 |
+
"""Calculate SimD quality without depending on the DALA assigner module."""
|
| 20 |
+
if priors.numel() == 0 or gt_bboxes.numel() == 0:
|
| 21 |
+
return priors.new_zeros((priors.shape[0], gt_bboxes.shape[0]))
|
| 22 |
+
|
| 23 |
+
prior_wh = (priors[:, 2:] - priors[:, :2]).clamp_min(eps)
|
| 24 |
+
gt_wh = (gt_bboxes[:, 2:] - gt_bboxes[:, :2]).clamp_min(eps)
|
| 25 |
+
prior_ctr = (priors[:, :2] + priors[:, 2:]) * 0.5
|
| 26 |
+
gt_ctr = (gt_bboxes[:, :2] + gt_bboxes[:, 2:]) * 0.5
|
| 27 |
+
|
| 28 |
+
wh_sum = (prior_wh[:, None, :] + gt_wh[None, :, :]).clamp_min(eps)
|
| 29 |
+
location = ((prior_ctr[:, None, :] - gt_ctr[None, :, :]) /
|
| 30 |
+
wh_sum).square().sum(dim=-1).sqrt()
|
| 31 |
+
shape = ((prior_wh[:, None, :] - gt_wh[None, :, :]) /
|
| 32 |
+
wh_sum).square().sum(dim=-1).sqrt()
|
| 33 |
+
return torch.exp(-(location + shape)).clamp_min(eps)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class FpnTinySupervisionCalibrator:
|
| 37 |
+
"""Compute FTSC-v1 weights for positives after hard assignment.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
mode: ``level``, ``quality`` or ``level_quality``.
|
| 41 |
+
lambda_level: Decay rate for scale-level octave mismatch.
|
| 42 |
+
alpha_level: Exponent applied to level compatibility.
|
| 43 |
+
beta_quality: Exponent applied to relative SimD quality.
|
| 44 |
+
weight_min: Lower clamp for raw positive weights.
|
| 45 |
+
weight_max: Upper clamp for raw positive weights.
|
| 46 |
+
normalize: If true, normalize positive weights to mean one.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def __init__(self,
|
| 50 |
+
mode: str = 'level_quality',
|
| 51 |
+
lambda_level: float = 1.0,
|
| 52 |
+
alpha_level: float = 1.0,
|
| 53 |
+
beta_quality: float = 1.0,
|
| 54 |
+
weight_min: float = 0.25,
|
| 55 |
+
weight_max: float = 2.0,
|
| 56 |
+
normalize: bool = True) -> None:
|
| 57 |
+
if mode not in {'level', 'quality', 'level_quality'}:
|
| 58 |
+
raise ValueError(
|
| 59 |
+
'FTSC mode must be one of level, quality, or level_quality')
|
| 60 |
+
if lambda_level < 0:
|
| 61 |
+
raise ValueError('lambda_level must be non-negative')
|
| 62 |
+
if weight_min <= 0 or weight_max <= 0:
|
| 63 |
+
raise ValueError('FTSC weight clamps must be positive')
|
| 64 |
+
if weight_min > weight_max:
|
| 65 |
+
raise ValueError('weight_min must not exceed weight_max')
|
| 66 |
+
self.mode = mode
|
| 67 |
+
self.lambda_level = lambda_level
|
| 68 |
+
self.alpha_level = alpha_level
|
| 69 |
+
self.beta_quality = beta_quality
|
| 70 |
+
self.weight_min = weight_min
|
| 71 |
+
self.weight_max = weight_max
|
| 72 |
+
self.normalize = normalize
|
| 73 |
+
|
| 74 |
+
@torch.no_grad()
|
| 75 |
+
def __call__(self, anchors: Tensor, level_ids: Tensor, gt_bboxes: Tensor,
|
| 76 |
+
pos_inds: Tensor, pos_assigned_gt_inds: Tensor) -> Tensor:
|
| 77 |
+
"""Return one FTSC weight per positive index."""
|
| 78 |
+
if len(pos_inds) == 0:
|
| 79 |
+
return anchors.new_zeros((0, ))
|
| 80 |
+
if level_ids is None:
|
| 81 |
+
raise ValueError('FTSC requires per-prior FPN level_ids')
|
| 82 |
+
|
| 83 |
+
pos_anchors = anchors[pos_inds]
|
| 84 |
+
pos_levels = level_ids[pos_inds].to(device=anchors.device,
|
| 85 |
+
dtype=torch.long)
|
| 86 |
+
pos_gt_bboxes = gt_bboxes[pos_assigned_gt_inds]
|
| 87 |
+
weights = anchors.new_ones((len(pos_inds), ))
|
| 88 |
+
|
| 89 |
+
if 'level' in self.mode:
|
| 90 |
+
weights = weights * self._level_weights(
|
| 91 |
+
anchors, level_ids.to(device=anchors.device,
|
| 92 |
+
dtype=torch.long), pos_levels,
|
| 93 |
+
pos_gt_bboxes)
|
| 94 |
+
|
| 95 |
+
if 'quality' in self.mode:
|
| 96 |
+
weights = weights * self._quality_weights(
|
| 97 |
+
pos_anchors, gt_bboxes, pos_assigned_gt_inds)
|
| 98 |
+
|
| 99 |
+
weights = weights.clamp(self.weight_min, self.weight_max)
|
| 100 |
+
if self.normalize and weights.numel() > 0:
|
| 101 |
+
weights = weights / weights.mean().clamp_min(1e-7)
|
| 102 |
+
return weights
|
| 103 |
+
|
| 104 |
+
def _level_weights(self, anchors: Tensor, level_ids: Tensor,
|
| 105 |
+
pos_levels: Tensor, pos_gt_bboxes: Tensor) -> Tensor:
|
| 106 |
+
prior_wh = (anchors[:, 2:] - anchors[:, :2]).clamp_min(1e-7)
|
| 107 |
+
prior_scale = torch.sqrt(prior_wh.prod(dim=-1).clamp_min(1e-7))
|
| 108 |
+
num_levels = int(level_ids.max().item()) + 1
|
| 109 |
+
canonical = prior_scale.new_ones((num_levels, ))
|
| 110 |
+
for level in level_ids.unique(sorted=True).tolist():
|
| 111 |
+
level_mask = level_ids == level
|
| 112 |
+
level_scales = prior_scale[level_mask]
|
| 113 |
+
canonical[level] = torch.exp(
|
| 114 |
+
torch.log(level_scales.clamp_min(1e-7)).mean())
|
| 115 |
+
|
| 116 |
+
gt_wh = (pos_gt_bboxes[:, 2:] -
|
| 117 |
+
pos_gt_bboxes[:, :2]).clamp_min(1e-7)
|
| 118 |
+
gt_scale = torch.sqrt(gt_wh.prod(dim=-1).clamp_min(1e-7))
|
| 119 |
+
octave_gap = torch.abs(
|
| 120 |
+
torch.log2(gt_scale / canonical[pos_levels].clamp_min(1e-7)))
|
| 121 |
+
level_weight = torch.exp(-self.lambda_level * octave_gap)
|
| 122 |
+
return level_weight.clamp_min(1e-7).pow(self.alpha_level)
|
| 123 |
+
|
| 124 |
+
def _quality_weights(self, pos_anchors: Tensor, gt_bboxes: Tensor,
|
| 125 |
+
pos_assigned_gt_inds: Tensor) -> Tensor:
|
| 126 |
+
quality_matrix = simd_quality(pos_anchors, gt_bboxes)
|
| 127 |
+
pos_quality = quality_matrix[
|
| 128 |
+
torch.arange(pos_anchors.shape[0], device=pos_anchors.device),
|
| 129 |
+
pos_assigned_gt_inds].clamp_min(1e-7)
|
| 130 |
+
gt_quality_sum = gt_bboxes.new_zeros((gt_bboxes.shape[0], ))
|
| 131 |
+
gt_quality_count = gt_bboxes.new_zeros((gt_bboxes.shape[0], ))
|
| 132 |
+
gt_quality_sum.scatter_add_(0, pos_assigned_gt_inds, pos_quality)
|
| 133 |
+
gt_quality_count.scatter_add_(
|
| 134 |
+
0, pos_assigned_gt_inds,
|
| 135 |
+
torch.ones_like(pos_quality, dtype=gt_quality_count.dtype))
|
| 136 |
+
gt_quality_mean = gt_quality_sum / gt_quality_count.clamp_min(1)
|
| 137 |
+
relative_quality = (
|
| 138 |
+
pos_quality /
|
| 139 |
+
gt_quality_mean[pos_assigned_gt_inds].clamp_min(1e-7))
|
| 140 |
+
return relative_quality.clamp_min(1e-7).pow(self.beta_quality)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
__all__ = ['FpnTinySupervisionCalibrator', 'simd_quality']
|
mmdet_code/mmdetection/projects/EfficientDet/configs/__pycache__/efficientdet_effb0_bifpn_dala_ftsc_f1_level_8xb16-crop512-100e_levir.cpython-313.pyc
ADDED
|
Binary file (796 Bytes). View file
|
|
|
mmdet_code/mmdetection/projects/EfficientDet/configs/__pycache__/efficientdet_effb0_bifpn_dala_ftsc_f2_quality_8xb16-crop512-100e_levir.cpython-313.pyc
ADDED
|
Binary file (862 Bytes). View file
|
|
|
mmdet_code/mmdetection/projects/EfficientDet/configs/__pycache__/efficientdet_effb0_bifpn_dala_ftsc_f3_level_quality_8xb16-crop512-100e_levir.cpython-313.pyc
ADDED
|
Binary file (862 Bytes). View file
|
|
|
mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_ftsc_f1_level_8xb16-crop512-100e_levir.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EfficientDet-D0 DALA + FTSC-F1 level compatibility weight.
|
| 2 |
+
|
| 3 |
+
FTSC-F1 keeps DALA's SimD/RLA/DWL assignment pipeline unchanged and only
|
| 4 |
+
calibrates positive loss weights by FPN scale-level compatibility.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
_base_ = './efficientdet_effb0_bifpn_dala_s0_control_8xb16-crop512-100e_levir.py'
|
| 8 |
+
|
| 9 |
+
model = dict(
|
| 10 |
+
bbox_head=dict(
|
| 11 |
+
use_ftsc=True,
|
| 12 |
+
ftsc_mode='level',
|
| 13 |
+
ftsc_lambda_level=1.0,
|
| 14 |
+
ftsc_alpha_level=1.0,
|
| 15 |
+
ftsc_beta_quality=1.0,
|
| 16 |
+
ftsc_weight_min=0.25,
|
| 17 |
+
ftsc_weight_max=2.0,
|
| 18 |
+
ftsc_normalize=True))
|
mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_ftsc_f2_quality_8xb16-crop512-100e_levir.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EfficientDet-D0 DALA + FTSC-F2 quality-normalized positive weight.
|
| 2 |
+
|
| 3 |
+
FTSC-F2 keeps DALA's SimD/RLA/DWL assignment pipeline unchanged and only
|
| 4 |
+
calibrates positive loss weights by each positive's SimD quality relative to
|
| 5 |
+
other positives assigned to the same GT.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
_base_ = './efficientdet_effb0_bifpn_dala_s0_control_8xb16-crop512-100e_levir.py'
|
| 9 |
+
|
| 10 |
+
model = dict(
|
| 11 |
+
bbox_head=dict(
|
| 12 |
+
use_ftsc=True,
|
| 13 |
+
ftsc_mode='quality',
|
| 14 |
+
ftsc_lambda_level=1.0,
|
| 15 |
+
ftsc_alpha_level=1.0,
|
| 16 |
+
ftsc_beta_quality=1.0,
|
| 17 |
+
ftsc_weight_min=0.25,
|
| 18 |
+
ftsc_weight_max=2.0,
|
| 19 |
+
ftsc_normalize=True))
|
mmdet_code/mmdetection/projects/EfficientDet/configs/efficientdet_effb0_bifpn_dala_ftsc_f3_level_quality_8xb16-crop512-100e_levir.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EfficientDet-D0 DALA + FTSC-F3 level and quality positive weight.
|
| 2 |
+
|
| 3 |
+
FTSC-F3 is the v1 full module: it keeps DALA's hard assignment unchanged, then
|
| 4 |
+
calibrates positive supervision by FPN scale-level compatibility multiplied by
|
| 5 |
+
quality-normalized SimD.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
_base_ = './efficientdet_effb0_bifpn_dala_s0_control_8xb16-crop512-100e_levir.py'
|
| 9 |
+
|
| 10 |
+
model = dict(
|
| 11 |
+
bbox_head=dict(
|
| 12 |
+
use_ftsc=True,
|
| 13 |
+
ftsc_mode='level_quality',
|
| 14 |
+
ftsc_lambda_level=1.0,
|
| 15 |
+
ftsc_alpha_level=1.0,
|
| 16 |
+
ftsc_beta_quality=1.0,
|
| 17 |
+
ftsc_weight_min=0.25,
|
| 18 |
+
ftsc_weight_max=2.0,
|
| 19 |
+
ftsc_normalize=True))
|
mmdet_code/mmdetection/projects/EfficientDet/tests/__pycache__/test_dala_efficientdet_head.cpython-313.pyc
CHANGED
|
Binary files a/mmdet_code/mmdetection/projects/EfficientDet/tests/__pycache__/test_dala_efficientdet_head.cpython-313.pyc and b/mmdet_code/mmdetection/projects/EfficientDet/tests/__pycache__/test_dala_efficientdet_head.cpython-313.pyc differ
|
|
|
mmdet_code/mmdetection/projects/EfficientDet/tests/test_dala_efficientdet_head.py
CHANGED
|
@@ -108,3 +108,73 @@ def test_dala_efficientdet_s3_preserves_fpn_level_ids():
|
|
| 108 |
assert label_weights[0].item() > 0
|
| 109 |
assert labels[1].item() == 1
|
| 110 |
assert label_weights[1].item() == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
assert label_weights[0].item() > 0
|
| 109 |
assert labels[1].item() == 1
|
| 110 |
assert label_weights[1].item() == 0
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_dala_efficientdet_ftsc_level_weight_prefers_scale_match():
|
| 114 |
+
head = DalaEfficientDetSepBNHead(
|
| 115 |
+
num_classes=1,
|
| 116 |
+
num_ins=2,
|
| 117 |
+
in_channels=8,
|
| 118 |
+
feat_channels=8,
|
| 119 |
+
stacked_convs=1,
|
| 120 |
+
norm_cfg=dict(type='BN'),
|
| 121 |
+
use_ftsc=True,
|
| 122 |
+
ftsc_mode='level',
|
| 123 |
+
ftsc_normalize=False,
|
| 124 |
+
anchor_generator=dict(
|
| 125 |
+
type='AnchorGenerator',
|
| 126 |
+
scales=[1],
|
| 127 |
+
ratios=[1.0],
|
| 128 |
+
strides=[8, 16]),
|
| 129 |
+
train_cfg=dict(
|
| 130 |
+
assigner=dict(type='DalaAssigner', sync_stats=False),
|
| 131 |
+
sampler=dict(type='PseudoSampler'),
|
| 132 |
+
allowed_border=-1,
|
| 133 |
+
pos_weight=-1))
|
| 134 |
+
|
| 135 |
+
anchors = torch.tensor([[0., 0., 10., 10.], [-15., -15., 25., 25.]])
|
| 136 |
+
level_ids = torch.tensor([0, 1])
|
| 137 |
+
gt_bboxes = torch.tensor([[0., 0., 10., 10.]])
|
| 138 |
+
weights = head._ftsc_positive_weights(
|
| 139 |
+
anchors,
|
| 140 |
+
level_ids,
|
| 141 |
+
gt_bboxes,
|
| 142 |
+
pos_inds=torch.tensor([0, 1]),
|
| 143 |
+
pos_assigned_gt_inds=torch.tensor([0, 0]))
|
| 144 |
+
|
| 145 |
+
assert weights[0] > weights[1]
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def test_dala_efficientdet_ftsc_quality_weight_prefers_better_simd():
|
| 149 |
+
head = DalaEfficientDetSepBNHead(
|
| 150 |
+
num_classes=1,
|
| 151 |
+
num_ins=1,
|
| 152 |
+
in_channels=8,
|
| 153 |
+
feat_channels=8,
|
| 154 |
+
stacked_convs=1,
|
| 155 |
+
norm_cfg=dict(type='BN'),
|
| 156 |
+
use_ftsc=True,
|
| 157 |
+
ftsc_mode='quality',
|
| 158 |
+
ftsc_normalize=False,
|
| 159 |
+
anchor_generator=dict(
|
| 160 |
+
type='AnchorGenerator',
|
| 161 |
+
scales=[1],
|
| 162 |
+
ratios=[1.0],
|
| 163 |
+
strides=[8]),
|
| 164 |
+
train_cfg=dict(
|
| 165 |
+
assigner=dict(type='DalaAssigner', sync_stats=False),
|
| 166 |
+
sampler=dict(type='PseudoSampler'),
|
| 167 |
+
allowed_border=-1,
|
| 168 |
+
pos_weight=-1))
|
| 169 |
+
|
| 170 |
+
anchors = torch.tensor([[0., 0., 10., 10.], [2., 2., 12., 12.]])
|
| 171 |
+
level_ids = torch.tensor([0, 0])
|
| 172 |
+
gt_bboxes = torch.tensor([[0., 0., 10., 10.]])
|
| 173 |
+
weights = head._ftsc_positive_weights(
|
| 174 |
+
anchors,
|
| 175 |
+
level_ids,
|
| 176 |
+
gt_bboxes,
|
| 177 |
+
pos_inds=torch.tensor([0, 1]),
|
| 178 |
+
pos_assigned_gt_inds=torch.tensor([0, 0]))
|
| 179 |
+
|
| 180 |
+
assert weights[0] > weights[1]
|
mmdet_code/mmdetection/tests/test_models/test_task_modules/__pycache__/test_ftsc_calibrator.cpython-313.pyc
ADDED
|
Binary file (3.48 kB). View file
|
|
|
mmdet_code/mmdetection/tests/test_models/test_task_modules/test_ftsc_calibrator.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) OpenMMLab. All rights reserved.
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
from mmdet.models.task_modules import FpnTinySupervisionCalibrator
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_ftsc_level_weight_prefers_scale_matched_level():
|
| 8 |
+
calibrator = FpnTinySupervisionCalibrator(
|
| 9 |
+
mode='level', normalize=False)
|
| 10 |
+
anchors = torch.tensor([
|
| 11 |
+
[0., 0., 10., 10.],
|
| 12 |
+
[-15., -15., 25., 25.],
|
| 13 |
+
])
|
| 14 |
+
level_ids = torch.tensor([0, 1])
|
| 15 |
+
gt_bboxes = torch.tensor([[0., 0., 10., 10.]])
|
| 16 |
+
|
| 17 |
+
weights = calibrator(
|
| 18 |
+
anchors,
|
| 19 |
+
level_ids,
|
| 20 |
+
gt_bboxes,
|
| 21 |
+
pos_inds=torch.tensor([0, 1]),
|
| 22 |
+
pos_assigned_gt_inds=torch.tensor([0, 0]))
|
| 23 |
+
|
| 24 |
+
assert weights[0] > weights[1]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_ftsc_quality_weight_prefers_better_simd_positive():
|
| 28 |
+
calibrator = FpnTinySupervisionCalibrator(
|
| 29 |
+
mode='quality', normalize=False)
|
| 30 |
+
anchors = torch.tensor([
|
| 31 |
+
[0., 0., 10., 10.],
|
| 32 |
+
[2., 2., 12., 12.],
|
| 33 |
+
])
|
| 34 |
+
level_ids = torch.tensor([0, 0])
|
| 35 |
+
gt_bboxes = torch.tensor([[0., 0., 10., 10.]])
|
| 36 |
+
|
| 37 |
+
weights = calibrator(
|
| 38 |
+
anchors,
|
| 39 |
+
level_ids,
|
| 40 |
+
gt_bboxes,
|
| 41 |
+
pos_inds=torch.tensor([0, 1]),
|
| 42 |
+
pos_assigned_gt_inds=torch.tensor([0, 0]))
|
| 43 |
+
|
| 44 |
+
assert weights[0] > weights[1]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def test_ftsc_normalizes_positive_weights_to_mean_one():
|
| 48 |
+
calibrator = FpnTinySupervisionCalibrator(
|
| 49 |
+
mode='level_quality', normalize=True)
|
| 50 |
+
anchors = torch.tensor([
|
| 51 |
+
[0., 0., 10., 10.],
|
| 52 |
+
[2., 2., 12., 12.],
|
| 53 |
+
[-15., -15., 25., 25.],
|
| 54 |
+
])
|
| 55 |
+
level_ids = torch.tensor([0, 0, 1])
|
| 56 |
+
gt_bboxes = torch.tensor([[0., 0., 10., 10.]])
|
| 57 |
+
|
| 58 |
+
weights = calibrator(
|
| 59 |
+
anchors,
|
| 60 |
+
level_ids,
|
| 61 |
+
gt_bboxes,
|
| 62 |
+
pos_inds=torch.tensor([0, 1, 2]),
|
| 63 |
+
pos_assigned_gt_inds=torch.tensor([0, 0, 0]))
|
| 64 |
+
|
| 65 |
+
assert torch.isfinite(weights).all()
|
| 66 |
+
assert torch.allclose(weights.mean(), torch.ones(()), atol=1e-6)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def test_ftsc_no_positive_returns_empty_weight_vector():
|
| 70 |
+
calibrator = FpnTinySupervisionCalibrator()
|
| 71 |
+
weights = calibrator(
|
| 72 |
+
anchors=torch.empty((0, 4)),
|
| 73 |
+
level_ids=torch.empty((0, ), dtype=torch.long),
|
| 74 |
+
gt_bboxes=torch.empty((0, 4)),
|
| 75 |
+
pos_inds=torch.empty((0, ), dtype=torch.long),
|
| 76 |
+
pos_assigned_gt_inds=torch.empty((0, ), dtype=torch.long))
|
| 77 |
+
|
| 78 |
+
assert weights.numel() == 0
|