Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the final XBNBlock-P2 module #4

Open
yangyahu-1994 opened this issue May 18, 2022 · 3 comments
Open

About the final XBNBlock-P2 module #4

yangyahu-1994 opened this issue May 18, 2022 · 3 comments

Comments

@yangyahu-1994
Copy link

image

Dear Professor Huang:
Hello! Is the final XBNBlock-P2 module the following code?

def GroupNorm(num_features, num_groups=32, eps=1e-5, affine=True, *args, **kwargs):
    if num_groups>num_features:
        print('------arrive maxum groub numbers of:', num_features)
        num_groups=num_features
    return nn.GroupNorm(num_groups, num_features, eps=eps, affine=affine)


class Bottleneck_XBNBlock_P2(nn.Module):
        expansion = 4
    
        def __init__(self, inplanes, planes, stride=1, downsample=None):
            super(Bottleneck_XBNBlock_P2, self).__init__()
            self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
            self.bn1 = nn.BatchNorm2d(planes)
            self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
            self.bn2 = GroupNorm(planes)
            self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
            self.bn3 = nn.BatchNorm2d(planes * 4)
            self.relu = nn.ReLU(inplace=True)
            self.downsample = downsample
            self.stride = stride

        def forward(self, x):
            residual = x
    
            out = self.conv1(x)
            out = self.bn1(out)
            out = self.relu(out)
    
            out = self.conv2(out)
            out = self.bn2(out)
            out = self.relu(out)
    
            out = self.conv3(out)
            out = self.bn3(out)
    
            if self.downsample is not None:
                residual = self.downsample(x)
    
            out += residual
            out = self.relu(out)
    
            return out

I read your code and only this class matches the module above.
Also, I use the standard Bottleneck in my work: conv 11->bn->relu->conv33->bn->relu. The structure of this Bottleneck is different from the one in your article. Can I replace the bn after 3*3 convolution with BFN(GN)?
Thank you very much.

@huangleiBuaa
Copy link
Owner

huangleiBuaa commented May 26, 2022

Hi, yes, the module you list is the XBNBlock-P2. You can replace the BN (after 33 convolution) with BFN in the standard 'basicBlock' (based on your description, you have only 2 conv, I am not sure whether you forget the other 11 conv), technicually. However, based on my experience on the Bottleneck, it seems that repalce the BN (after 1*1 convolution) with BFN should be better in your standard 'basicBlock'.

@yangyahu-1994
Copy link
Author

非常感谢黄老师的耐心解答。
我的Bottleneck如下图:
image
确实只有两个Conv。我前几天将33convolution之后的BN换成了BFN,效果确实没有以前好了。我再试试11convolution之后的BN换成BFN。
谢谢黄老师。

@Sakura0v01
Copy link

同学你好,我想请问一下关于下载下来的代码ResNext_XBNBlock_P2.py中model_urls没有定义是如何解决的
L0HKCT5ZNMO53AQ8XGXED

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

No branches or pull requests

3 participants