Skip to content

Commit

Permalink
Update to remove type in recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
sungchul2 committed Apr 29, 2024
1 parent c9a8562 commit ec44eb9
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/otx/algo/detection/heads/yolox_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(
self.train_cfg = train_cfg

if self.train_cfg:
self.assigner = SimOTAAssigner(center_radius=2.5)
self.assigner = SimOTAAssigner(**self.train_cfg["assigner"])
# YOLOX does not support sampling
self.sampler = PseudoSampler() # type: ignore[no-untyped-call]

Expand Down
9 changes: 1 addition & 8 deletions src/otx/algo/detection/mmconfigs/yolox_l.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
load_from: https://download.openmmlab.com/mmdetection/v2.0/yolox/yolox_l_8x8_300e_coco/yolox_l_8x8_300e_coco_20211126_140236-d3bd2b23.pth
train_cfg:
assigner:
type: SimOTAAssigner
center_radius: 2.5
test_cfg:
score_thr: 0.01
nms:
type: nms
iou_threshold: 0.65
max_per_img: 100
type: YOLOX
max_per_img: 10
data_preprocessor:
type: DetDataPreprocessor
non_blocking: true
mean:
- 0.0
Expand All @@ -25,23 +21,20 @@ data_preprocessor:
bgr_to_rgb: false
pad_size_divisor: 32
backbone:
type: CSPDarknet
deepen_factor: 1.0
widen_factor: 1.0
out_indices:
- 2
- 3
- 4
neck:
type: YOLOXPAFPN
in_channels:
- 256
- 512
- 1024
out_channels: 256
num_csp_blocks: 3
bbox_head:
type: YOLOXHead
num_classes: 80
in_channels: 256
feat_channels: 256
9 changes: 1 addition & 8 deletions src/otx/algo/detection/mmconfigs/yolox_s.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
load_from: https://download.openmmlab.com/mmdetection/v2.0/yolox/yolox_s_8x8_300e_coco/yolox_s_8x8_300e_coco_20211121_095711-4592a793.pth
train_cfg:
assigner:
type: SimOTAAssigner
center_radius: 2.5
test_cfg:
score_thr: 0.01
nms:
type: nms
iou_threshold: 0.65
max_per_img: 100
type: YOLOX
max_per_img: 10
data_preprocessor:
type: DetDataPreprocessor
non_blocking: true
mean:
- 0.0
Expand All @@ -25,23 +21,20 @@ data_preprocessor:
bgr_to_rgb: false
pad_size_divisor: 32
backbone:
type: CSPDarknet
deepen_factor: 0.33
widen_factor: 0.5
out_indices:
- 2
- 3
- 4
neck:
type: YOLOXPAFPN
in_channels:
- 128
- 256
- 512
out_channels: 128
num_csp_blocks: 4
bbox_head:
type: YOLOXHead
num_classes: 80
in_channels: 128
feat_channels: 128
9 changes: 1 addition & 8 deletions src/otx/algo/detection/mmconfigs/yolox_tiny.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
load_from: https://storage.openvinotoolkit.org/repositories/openvino_training_extensions/models/object_detection/v2/yolox_tiny_8x8.pth
train_cfg:
assigner:
type: SimOTAAssigner
center_radius: 2.5
test_cfg:
score_thr: 0.01
nms:
type: nms
iou_threshold: 0.65
max_per_img: 100
type: YOLOX
max_per_img: 10
data_preprocessor:
type: DetDataPreprocessor
non_blocking: true
mean:
- 123.675
Expand All @@ -25,23 +21,20 @@ data_preprocessor:
bgr_to_rgb: false
pad_size_divisor: 32
backbone:
type: CSPDarknet
deepen_factor: 0.33
widen_factor: 0.375
out_indices:
- 2
- 3
- 4
neck:
type: YOLOXPAFPN
in_channels:
- 96
- 192
- 384
out_channels: 96
num_csp_blocks: 1
bbox_head:
type: YOLOXHead
num_classes: 80
in_channels: 96
feat_channels: 96
9 changes: 1 addition & 8 deletions src/otx/algo/detection/mmconfigs/yolox_x.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
load_from: https://download.openmmlab.com/mmdetection/v2.0/yolox/yolox_x_8x8_300e_coco/yolox_x_8x8_300e_coco_20211126_140254-1ef88d67.pth
train_cfg:
assigner:
type: SimOTAAssigner
center_radius: 2.5
test_cfg:
score_thr: 0.01
nms:
type: nms
iou_threshold: 0.65
max_per_img: 100
type: YOLOX
max_per_img: 10
data_preprocessor:
type: DetDataPreprocessor
non_blocking: true
mean:
- 0.0
Expand All @@ -25,23 +21,20 @@ data_preprocessor:
bgr_to_rgb: false
pad_size_divisor: 32
backbone:
type: CSPDarknet
deepen_factor: 1.33
widen_factor: 1.25
out_indices:
- 2
- 3
- 4
neck:
type: YOLOXPAFPN
in_channels:
- 320
- 640
- 1280
out_channels: 320
num_csp_blocks: 4
bbox_head:
type: YOLOXHead
num_classes: 80
in_channels: 320
feat_channels: 320
6 changes: 0 additions & 6 deletions src/otx/algo/detection/yolox.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,21 @@ class YOLOX(SingleStageDetector):

def build_backbone(self, cfg: ConfigDict | dict) -> nn.Module:
"""Build backbone."""
cfg.pop("type") # TODO (sungchul): remove `type` in recipe
return CSPDarknet(**cfg)

def build_neck(self, cfg: ConfigDict | dict) -> nn.Module:
"""Build neck."""
cfg.pop("type") # TODO (sungchul): remove `type` in recipe
return YOLOXPAFPN(**cfg)

def build_bbox_head(self, cfg: ConfigDict | dict) -> nn.Module:
"""Build bbox head."""
cfg.pop("type") # TODO (sungchul): remove `type` in recipe
return YOLOXHead(**cfg)

def build_det_data_preprocessor(self, cfg: ConfigDict | dict) -> nn.Module:
"""Build DetDataPreprocessor.
TODO (sungchul): DetDataPreprocessor will be removed.
"""
cfg.pop("type") # TODO (sungchul): remove `type` in recipe
return DetDataPreprocessor(**cfg)


Expand Down Expand Up @@ -104,7 +100,6 @@ def _create_model(self) -> nn.Module:

config = deepcopy(self.config)
self.classification_layers = self.get_classification_layers(config, "model.")
config.pop("type") # TODO (sungchul): remove `type` in recipe
detector = YOLOX(**convert_conf_to_mmconfig_dict(config))
detector.init_weights()
if self.load_from is not None:
Expand Down Expand Up @@ -215,7 +210,6 @@ def get_classification_layers(
Normally it is related with background classes.
"""
sample_config = deepcopy(config)
sample_config.pop("type") # TODO (sungchul): remove `type` in recipe
modify_num_classes(sample_config, 5)
sample_model_dict = YOLOX(**convert_conf_to_mmconfig_dict(sample_config)).state_dict()

Expand Down
1 change: 0 additions & 1 deletion tests/unit/algo/detection/heads/test_yolox_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_loss_by_feat(self):
train_cfg = Config(
{
"assigner": {
"type": "SimOTAAssigner",
"center_radius": 2.5,
"candidate_topk": 10,
"iou_weight": 3.0,
Expand Down

0 comments on commit ec44eb9

Please sign in to comment.