Skip to content

Commit 5507bdc

Browse files
MILK-BIOSPillar1989
authored andcommitted
Refractor: Call the base conv directly
1 parent c495b16 commit 5507bdc

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

sscma/models/backbones/MobileNetv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(
7272

7373
self.layers = []
7474
for idx, (t, c, n, s) in enumerate(inverted_residual_setting):
75-
out_channels = _make_divisible(c * widen_factor, round_nearest) * (2 if rep else 1)
75+
out_channels = _make_divisible(c * widen_factor, round_nearest) # * (2 if rep else 1) why times 2?
7676
tmp_layers = []
7777
for i in range(n):
7878
stride = s if i == 0 else 1

sscma/models/backbones/csp_darknet.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import torch
66
from mmdet.utils import ConfigType, OptMultiConfig
77

8-
from sscma.models.base import ConvModule
8+
from sscma.models.base import ConvNormActivation
99
from sscma.models.layers import CSPLayer, SPPFBottleneck
1010
from sscma.models.utils import make_divisible, make_round
1111
from sscma.registry import MODELS
@@ -61,14 +61,14 @@ def __init__(
6161
)
6262

6363
def build_stem_layer(self):
64-
return ConvModule(
64+
return ConvNormActivation(
6565
self.input_channels,
6666
make_divisible(self.arch_settings[self.arch][0][0], self.widen_factor),
6767
kernel_size=6,
6868
stride=2,
6969
padding=2,
70-
norm_cfg=self.norm_cfg,
71-
act_cfg=self.act_cfg,
70+
norm_layer=self.norm_cfg,
71+
activation_layer=self.act_cfg,
7272
)
7373

7474
def build_stage_layer(self, stage_idx: int, setting: list) -> list:
@@ -78,8 +78,14 @@ def build_stage_layer(self, stage_idx: int, setting: list) -> list:
7878
out_channels = make_divisible(out_channels, self.widen_factor)
7979
num_blocks = make_round(num_blocks)
8080
stage = []
81-
conv_layer = ConvModule(
82-
in_channels, out_channels, kernel_size=3, stride=2, padding=1, norm_cfg=self.norm_cfg, act_cfg=self.act_cfg
81+
conv_layer = ConvNormActivation(
82+
in_channels,
83+
out_channels,
84+
kernel_size=3,
85+
stride=2,
86+
padding=1,
87+
norm_layer=self.norm_cfg,
88+
activation_layer=self.act_cfg,
8389
)
8490
stage.append(conv_layer)
8591

sscma/models/heads/yolov5_head.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def loss_by_feat(
520520

521521
# no gt bbox matches anchor
522522
if batch_targets_scaled.shape[0] == 0:
523-
loss_box += bbox_preds[i].sum() * 0
523+
loss_box += bbox_preds[i].sum() * 0 # why not + 0 directly
524524
loss_cls += cls_scores[i].sum() * 0
525525
loss_obj += self.loss_obj(objectnesses[i], target_obj) * self.obj_level_weights[i]
526526
continue

sscma/models/layers/sppf.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mmengine.model import BaseModule
99
from torch import Tensor
1010

11-
from ..base import ConvModule
11+
from ..base import ConvNormActivation
1212

1313

1414
class SPPFBottleneck(BaseModule):
@@ -28,8 +28,14 @@ def __init__(
2828

2929
if use_conv_first:
3030
mid_channels = int(in_channels * mid_channels_scale)
31-
self.conv1 = ConvModule(
32-
in_channels, mid_channels, 1, stride=1, conv_cfg=conv_cfg, norm_cfg=norm_cfg, act_cfg=act_cfg
31+
self.conv1 = ConvNormActivation(
32+
in_channels,
33+
mid_channels,
34+
1,
35+
stride=1,
36+
conv_layer=conv_cfg,
37+
norm_layer=norm_cfg,
38+
activation_layer=act_cfg,
3339
)
3440
else:
3541
mid_channels = in_channels
@@ -44,8 +50,8 @@ def __init__(
4450
)
4551
conv2_in_channels = mid_channels * (len(kernel_sizes) + 1)
4652

47-
self.conv2 = ConvModule(
48-
conv2_in_channels, out_channels, 1, conv_cfg=conv_cfg, norm_cfg=norm_cfg, act_cfg=act_cfg
53+
self.conv2 = ConvNormActivation(
54+
conv2_in_channels, out_channels, 1, conv_layer=conv_cfg, norm_layer=norm_cfg, activation_layer=act_cfg
4955
)
5056

5157
def forward(self, x: Tensor) -> Tensor:

sscma/models/necks/fpn.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from sscma.registry import NECKS
1717

18-
from ..base import ConvModule
18+
from ..base import ConvNormActivation
1919
from ..layers import CSPLayer
2020
from ..utils import make_divisible, make_round
2121

@@ -416,12 +416,12 @@ def build_reduce_layer(self, idx: int) -> nn.Module:
416416
nn.Module: The reduce layer.
417417
"""
418418
if idx == len(self.in_channels) - 1:
419-
layer = ConvModule(
419+
layer = ConvNormActivation(
420420
make_divisible(self.in_channels[idx], self.widen_factor),
421421
make_divisible(self.in_channels[idx - 1], self.widen_factor),
422422
1,
423-
norm_cfg=self.norm_cfg,
424-
act_cfg=self.act_cfg,
423+
norm_layer=self.norm_cfg,
424+
activation_layer=self.act_cfg,
425425
)
426426
else:
427427
layer = nn.Identity()
@@ -461,12 +461,12 @@ def build_top_down_layer(self, idx: int):
461461
norm_cfg=self.norm_cfg,
462462
act_cfg=self.act_cfg,
463463
),
464-
ConvModule(
464+
ConvNormActivation(
465465
make_divisible(self.in_channels[idx - 1], self.widen_factor),
466466
make_divisible(self.in_channels[idx - 2], self.widen_factor),
467467
kernel_size=1,
468-
norm_cfg=self.norm_cfg,
469-
act_cfg=self.act_cfg,
468+
norm_layer=self.norm_cfg,
469+
activation_layer=self.act_cfg,
470470
),
471471
)
472472

@@ -479,14 +479,14 @@ def build_downsample_layer(self, idx: int) -> nn.Module:
479479
Returns:
480480
nn.Module: The downsample layer.
481481
"""
482-
return ConvModule(
482+
return ConvNormActivation(
483483
make_divisible(self.in_channels[idx], self.widen_factor),
484484
make_divisible(self.in_channels[idx], self.widen_factor),
485485
kernel_size=3,
486486
stride=2,
487487
padding=1,
488-
norm_cfg=self.norm_cfg,
489-
act_cfg=self.act_cfg,
488+
norm_layer=self.norm_cfg,
489+
activation_layer=self.act_cfg,
490490
)
491491

492492
def build_bottom_up_layer(self, idx: int) -> nn.Module:

tools/train.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ def main():
193193
args, cfg = build_config(args)
194194

195195
if 'runner_type' not in cfg:
196-
from mmengine.runner import Runner
196+
from sscma.engine import Runner
197197

198198
runner = Runner.from_cfg(cfg)
199199
runner.val_evaluator.dataset_meta = runner.val_dataloader.dataset.METAINFO
200200
else:
201-
from mmengine.registry import RUNNERS
201+
from sscma.registry import RUNNERS
202202

203203
runner = RUNNERS.build(cfg)
204204
runner.val_evaluator.dataset_meta = runner.val_dataloader.dataset.METAINFO

0 commit comments

Comments
 (0)