Skip to content

Commit bda8ab0

Browse files
committed
Remove min channels for SelectiveKernel, divisor should cover cases well enough.
1 parent a27f4ae commit bda8ab0

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

timm/models/layers/selective_kernel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def forward(self, x):
4949
class SelectiveKernel(nn.Module):
5050

5151
def __init__(self, in_channels, out_channels=None, kernel_size=None, stride=1, dilation=1, groups=1,
52-
rd_ratio=1./16, rd_channels=None, min_rd_channels=32, rd_divisor=8, keep_3x3=True, split_input=True,
52+
rd_ratio=1./16, rd_channels=None, rd_divisor=8, keep_3x3=True, split_input=True,
5353
drop_block=None, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, aa_layer=None):
5454
""" Selective Kernel Convolution Module
5555
@@ -68,7 +68,6 @@ def __init__(self, in_channels, out_channels=None, kernel_size=None, stride=1, d
6868
dilation (int): dilation for module as a whole, impacts dilation of each branch
6969
groups (int): number of groups for each branch
7070
rd_ratio (int, float): reduction factor for attention features
71-
min_rd_channels (int): minimum attention feature channels
7271
keep_3x3 (bool): keep all branch convolution kernels as 3x3, changing larger kernels for dilations
7372
split_input (bool): split input channels evenly across each convolution branch, keeps param count lower,
7473
can be viewed as grouping by path, output expands to module out_channels count
@@ -103,8 +102,7 @@ def __init__(self, in_channels, out_channels=None, kernel_size=None, stride=1, d
103102
ConvBnAct(in_channels, out_channels, kernel_size=k, dilation=d, **conv_kwargs)
104103
for k, d in zip(kernel_size, dilation)])
105104

106-
attn_channels = rd_channels or make_divisible(
107-
out_channels * rd_ratio, min_value=min_rd_channels, divisor=rd_divisor)
105+
attn_channels = rd_channels or make_divisible(out_channels * rd_ratio, divisor=rd_divisor)
108106
self.attn = SelectiveKernelAttn(out_channels, self.num_paths, attn_channels)
109107
self.drop_block = drop_block
110108

timm/models/sknet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def skresnet18(pretrained=False, **kwargs):
153153
Different from configs in Select Kernel paper or "Compounding the Performance Improvements..." this
154154
variation splits the input channels to the selective convolutions to keep param count down.
155155
"""
156-
sk_kwargs = dict(min_rd_channels=16, rd_ratio=1/8, split_input=True)
156+
sk_kwargs = dict(rd_ratio=1 / 8, rd_divisor=16, split_input=True)
157157
model_args = dict(
158158
block=SelectiveKernelBasic, layers=[2, 2, 2, 2], block_args=dict(sk_kwargs=sk_kwargs),
159159
zero_init_last_bn=False, **kwargs)
@@ -167,7 +167,7 @@ def skresnet34(pretrained=False, **kwargs):
167167
Different from configs in Select Kernel paper or "Compounding the Performance Improvements..." this
168168
variation splits the input channels to the selective convolutions to keep param count down.
169169
"""
170-
sk_kwargs = dict(min_rd_channels=16, rd_ratio=1/8, split_input=True)
170+
sk_kwargs = dict(rd_ratio=1 / 8, rd_divisor=16, split_input=True)
171171
model_args = dict(
172172
block=SelectiveKernelBasic, layers=[3, 4, 6, 3], block_args=dict(sk_kwargs=sk_kwargs),
173173
zero_init_last_bn=False, **kwargs)
@@ -207,7 +207,7 @@ def skresnext50_32x4d(pretrained=False, **kwargs):
207207
"""Constructs a Select Kernel ResNeXt50-32x4d model. This should be equivalent to
208208
the SKNet-50 model in the Select Kernel Paper
209209
"""
210-
sk_kwargs = dict(min_rd_channels=32, rd_ratio=1/16, split_input=False)
210+
sk_kwargs = dict(rd_ratio=1/16, rd_divisor=32, split_input=False)
211211
model_args = dict(
212212
block=SelectiveKernelBottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4,
213213
block_args=dict(sk_kwargs=sk_kwargs), zero_init_last_bn=False, **kwargs)

0 commit comments

Comments
 (0)