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

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

Open
tianyuluan opened this issue Mar 20, 2020 · 4 comments

Comments

@tianyuluan
Copy link

No description provided.

@iamhankai
Copy link
Owner

Replace nn.Conv2d with GhostModule

class GhostModule(nn.Module):

@LexTran
Copy link

LexTran commented Mar 29, 2020

@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!

@Tangzhaotz
Copy link

i have same quetion ,do you solve the problem?

@iamhankai
Copy link
Owner

@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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants