“DataParallel”对象没有属性“conv1”

我正在尝试conv1根据下面的代码和架构可视化层的 cnn 网络特征图。它在没有 DataParallel 的情况下正常工作,但是当我激活model = nn.DataParallel(model)它时,它会引发错误:“DataParallel”对象没有属性“conv1”。任何建议表示赞赏。


class Model(nn.Module):

    def __init__(self, kernel, num_filters, res = ResidualBlock):

        super(Model, self).__init__()

        

        self.conv0 = nn.Sequential(

            nn.Conv2d(4, num_filters, kernel_size = kernel*3, 

                       padding = 4),

            nn.BatchNorm2d(num_filters),

            nn.ReLU(inplace=True))

        

        self.conv1 = nn.Sequential(

            nn.Conv2d(num_filters, num_filters*2, kernel_size = kernel, 

                      stride=2, padding = 1),

            nn.BatchNorm2d(num_filters*2),

            nn.ReLU(inplace=True))

        

        self.conv2 = nn.Sequential(

            nn.Conv2d(num_filters*2, num_filters*4, kernel_size = kernel, stride=2, padding = 1),

            nn.BatchNorm2d(num_filters*4),

            nn.ReLU(inplace=True))

               

        self.tsconv0 = nn.Sequential(

            nn.ConvTranspose2d(num_filters*4, num_filters*2, kernel_size = kernel, padding = 1),

            nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True),

            nn.ReLU(inplace=True),

            nn.BatchNorm2d(num_filters*2))


        self.tsconv1 = nn.Sequential(

            nn.ConvTranspose2d(num_filters*2, num_filters, kernel_size = kernel, padding = 1),

            nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True),

            nn.ReLU(inplace=True),

            nn.BatchNorm2d(num_filters))

        

        self.tsconv2 = nn.Sequential(

            nn.Conv2d(num_filters, 1, kernel_size = kernel*3, padding = 4, bias=False),

            nn.ReLU(inplace=True))


model = Model(kernel, num_filters)

model = nn.DataParallel(model)




慕尼黑8549860
浏览 86回答 1
1回答

料青山看我应如是

当您使用 时DataParallel,请在此处添加额外的内容module。而不是model.conv3.简单地写model.module.conv3.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python