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

代码中未找到IBE模块的theta2参数? #11

Open
wsy-yjys opened this issue Oct 18, 2023 · 6 comments
Open

代码中未找到IBE模块的theta2参数? #11

wsy-yjys opened this issue Oct 18, 2023 · 6 comments

Comments

@wsy-yjys
Copy link

class IBEConvModule(BaseModule):
    def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
                 padding=1, dilation=1, groups=1, bias=False, act_cfg=None, **kwargs):

        super(IBEConvModule, self).__init__() 
        self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias)
        # self.att = DifferenceAttention(out_channels, out_channels, out_channels)

        self.bn = nn.BatchNorm2d(out_channels)
        self.bn2 = nn.BatchNorm2d(out_channels)

        self.act = build_activation_layer(act_cfg) #nn.ReLU()
        self.theta = Parameter(torch.zeros([1]))

    def merge_bn(self, conv, bn):
        conv_w = conv
        conv_b = torch.zeros_like(bn.running_mean)

        factor = bn.weight / torch.sqrt(bn.running_var + bn.eps)
        weight = nn.Parameter(conv_w *
                                factor.reshape([conv_w.shape[0], 1, 1, 1]))
        bias = nn.Parameter((conv_b - bn.running_mean) * factor + bn.bias)
        return weight, bias

    def forward(self, x):
        # if self.training:
        out_normal = self.conv(x)
        [C_out, C_in, kernel_size, kernel_size] = self.conv.weight.shape
        kernel_diff = self.conv.weight.sum(2).sum(2)        # 每层kernel的权重和   [C_out, C_in]
        kernel_diff = kernel_diff[:, :, None, None]
        out_diff = F.conv2d(input=x, weight=kernel_diff, stride=self.conv.stride, padding=0, groups=self.conv.groups)

        theta = F.sigmoid(self.theta)#[None, :, None, None]
        # outs = self.att(out_normal, out_normal - theta * out_diff)
        outs = self.bn(out_normal) + self.bn2(out_normal - theta * out_diff)
        # outs = self.bn(out_normal) - theta * self.bn2(out_diff)
        # else:
        #     weight_conv = self.conv.weight

        #     theta = F.sigmoid(self.theta)#[:, None, None, None]
        #     kernel_diff = theta * self.conv.weight.sum(2).sum(2)[:, :, None, None]
        #     weight_diff = self.conv.weight - nn.ZeroPad2d(1)(kernel_diff)

        #     weight_conv, bias_conv = self.merge_bn(weight_conv, self.bn)
        #     weight_diff, bias_diff = self.merge_bn(weight_diff, self.bn2)
        #     weight_final = weight_conv + weight_diff
        #     bias_final = bias_conv + bias_diff

        #     outs = F.conv2d(input=x, weight=weight_final, bias=bias_final, stride=self.conv.stride, padding=self.conv.padding, groups=self.conv.groups)
        #     # outs = self.act(outs)

        return self.act(outs)

在上述的代码中,找不到论文中所说的theta2?
image

@ghost
Copy link

ghost commented Oct 18, 2023

Setting theta2 to 1 is a special case.

@wsy-yjys
Copy link
Author

wsy-yjys commented Oct 18, 2023 via email

@ghost
Copy link

ghost commented Oct 18, 2023

These codes are useful when deploying FemtoDet. I was so busy releasing the codes that I forgot to recover them.

@wsy-yjys
Copy link
Author

wsy-yjys commented Oct 18, 2023 via email

@wsy-yjys
Copy link
Author

您好,还有一个问题想请教下您,请问theta的作用是什么,《Pixel Difference Networks for Efficient Edge Detection》中源码实现并没有这一参数,期待您的回复~

@yh-pengtu
Copy link
Owner

yh-pengtu commented Oct 19, 2023 via email

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

2 participants