ghostnet.pytorch icon indicating copy to clipboard operation
ghostnet.pytorch copied to clipboard

hello! how to move the GhostModule to my net to replace the normal conv2d layer?

Open tianyuluan opened this issue 4 years ago • 4 comments

tianyuluan avatar Mar 20 '20 13:03 tianyuluan

Replace nn.Conv2d with GhostModule https://github.com/iamhankai/ghostnet.pytorch/blob/2c90e67d8c33c44ec1bad12c9686f645b0d4de08/ghost_net.py#L55

iamhankai avatar Mar 21 '20 01:03 iamhankai

@iamhankai Hi, thanks for doing such a great work. I was trying to do the same thing as thianyuluan does. I notice that you said replace nn.Conv2d with GhostModule, how does the parameters set? Should I change any of that? if my code is like:

def conv(in_channels, out_channels, kernel_size=3, padding=1, bn=True, dilation=1, stride=1, relu=True, bias=True):
    modules = [nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias)]
    if bn:
        modules.append(nn.BatchNorm2d(out_channels))
    if relu:
        modules.append(nn.ReLU(inplace=True))
    return nn.Sequential(*modules)

I just need to change it into this?:

def conv(in_channels, out_channels, kernel_size=3, padding=1, bn=True, dilation=1, stride=1, relu=True, bias=True):
    modules = [GhostModule(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias)]
    if bn:
        modules.append(nn.BatchNorm2d(out_channels))
    if relu:
        modules.append(nn.ReLU(inplace=True))
    return nn.Sequential(*modules)

Is that ok? Hope to get your help, thanks a lot!

LexTran avatar Mar 29 '20 16:03 LexTran

i have same quetion ,do you solve the problem?

Tangzhaotz avatar Jul 29 '20 01:07 Tangzhaotz

@LexTran Just change to:

def conv(in_channels, out_channels, kernel_size=3, padding=1, bn=True, dilation=1, stride=1, relu=True, bias=True):
    modules = [GhostModule(in_channels, out_channels, kernel_size, stride=stride)]
    if bn:
        modules.append(nn.BatchNorm2d(out_channels))
    if relu:
        modules.append(nn.ReLU(inplace=True))
    return nn.Sequential(*modules)

iamhankai avatar Jul 29 '20 03:07 iamhankai