遇到问题EGNet(6):

def forward里面的内容不显示吗?当调用vgg的是后会显示,默认是resnet


class vgg16(nn.Module):
    def __init__(self):
        super(vgg16, self).__init__()
        self.cfg = {'tun': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M'],
                    'tun_ex': [512, 512, 512]}
        self.extract = [8, 15, 22, 29]  # feature map in 'tun' -> c(2), c(3), c(4), c(5)   # [3, 8, 15, 22, 29]
        self.extract_ex = [5]
        self.base = nn.ModuleList(vgg(self.cfg['tun'], 3))
        self.base_ex = vgg_ex(self.cfg['tun_ex'], 512)
        # init paramiter
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
                m.weight.data.normal_(0, 0.01)
            elif isinstance(m, nn.BatchNorm2d):
                m.weight.data.fill_(1)
                m.bias.data.zero_()

    def load_pretrained_model(self, model):
        self.base.load_state_dict(model)

    def forward(self, x, multi=0):
        tmp_x = []
        # through the 'tun' layer by layer
        for k in range(len(self.base)):  # 'tun' 37 layer -> 64 64, 128 128, 256 256 256, 512 512 512, 512 512 512
            print('=>len(self.base)', len(self.base))  # not show ???
            x = self.base[k](x)  # get new x through every layer in 'tun'
            if k in self.extract:  # feature map in 'tun' -> c(2), c(3), c(4), c(5) -> self.extract = [8, 15, 22, 29]
                tmp_x.append(x)
        x = self.base_ex(x)  # 'tun_ex' layer -> 512 512 512
        tmp_x.append(x)  # # feature map in 'tun_ex' -> c(6)
        if multi == 1:
            tmp_y = []
            tmp_y.append(tmp_x[0])  # feature map in 'tun' -> c(2)
            return tmp_y
        else:
            return tmp_x

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

计算机视觉-Archer

图像分割没有团队的同学可加群

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值