Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Stride=1 cfg Kernel Sizes Never Used? #25

Closed
glenn-jocher opened this issue Apr 18, 2020 · 2 comments
Closed

Stride=1 cfg Kernel Sizes Never Used? #25

glenn-jocher opened this issue Apr 18, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@glenn-jocher
Copy link
Contributor

glenn-jocher commented Apr 18, 2020

The first column of the cfg are k kernel sizes:

cfgs = [
# k, t, c, SE, s
[3, 16, 16, 0, 1],
[3, 48, 24, 0, 2],
[3, 72, 24, 0, 1],
[5, 72, 40, 1, 2],
[5, 120, 40, 1, 1],
[3, 240, 80, 0, 2],
[3, 200, 80, 0, 1],
[3, 184, 80, 0, 1],
[3, 184, 80, 0, 1],
[3, 480, 112, 1, 1],
[3, 672, 112, 1, 1],
[5, 672, 160, 1, 2],
[5, 960, 160, 0, 1],
[5, 960, 160, 1, 1],
[5, 960, 160, 0, 1],
[5, 960, 160, 1, 1]
]
return GhostNet(cfgs, **kwargs)

But unless stride=2, it appears GhostBottleneck() module does not use the cfg kernel size. Is this correct? If so setting these to 1 in the cfg may be more clear?

class GhostBottleneck(nn.Module):
def __init__(self, inp, hidden_dim, oup, kernel_size, stride, use_se):
super(GhostBottleneck, self).__init__()
assert stride in [1, 2]
self.conv = nn.Sequential(
# pw
GhostModule(inp, hidden_dim, kernel_size=1, relu=True),
# dw
depthwise_conv(hidden_dim, hidden_dim, kernel_size, stride, relu=False) if stride==2 else nn.Sequential(),
# Squeeze-and-Excite
SELayer(hidden_dim) if use_se else nn.Sequential(),
# pw-linear
GhostModule(hidden_dim, oup, kernel_size=1, relu=False),
)
if stride == 1 and inp == oup:
self.shortcut = nn.Sequential()
else:
self.shortcut = nn.Sequential(
depthwise_conv(inp, inp, kernet_size, stride, relu=False),
nn.Conv2d(inp, oup, 1, 1, 0, bias=False),
nn.BatchNorm2d(oup),
)
def forward(self, x):
return self.conv(x) + self.shortcut(x)

@iamhankai iamhankai added the duplicate This issue or pull request already exists label Apr 19, 2020
@iamhankai
Copy link
Owner

You are right. The code is not clean... As said in huawei-noah/Efficient-AI-Backbones#12

@glenn-jocher
Copy link
Contributor Author

@iamhankai ok got it, thank you! Was just checking to make sure I wasn't missing something.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants