最近发表的话题
最近发表的评论
  • 关于 pytorch 中.eval () 的问题 at 1个月前

    class DoubleConv(nn.Module):
    def init(self, in_ch, out_ch):
    super(DoubleConv, self).init()
    self.conv = nn.Sequential(
    nn.Conv2d(in_ch, out_ch, 3, padding=1),
    nn.BatchNorm2d(out_ch),
    nn.ReLU(inplace=True),
    nn.Conv2d(out_ch, out_ch, 3, padding=1),
    nn.BatchNorm2d(out_ch),
    nn.ReLU(inplace=True)
    )

    def forward(self, input):
        return self.conv(input)

    class UNet(nn.Module):
    def init(self,in_ch,out_ch):
    super(UNet, self).init()

        self.conv1 = DoubleConv(in_ch, 64)
        self.down1 = nn.MaxPool2d(2)
        self.conv2 = DoubleConv(64, 128)
        self.down2 = nn.MaxPool2d(2)
        self.conv3 = DoubleConv(128, 256)
        self.down3 = nn.MaxPool2d(2)
        self.conv4 = DoubleConv(256, 512)
        self.down4 = nn.MaxPool2d(2)
        self.conv5 = DoubleConv(512, 1024)
        self.up6 = nn.ConvTranspose2d(1024, 512, 2, stride=2)
        self.conv6 = DoubleConv(1024, 512)
        self.up7 = nn.ConvTranspose2d(512, 256, 2, stride=2)
        self.conv7 = DoubleConv(512, 256)
        self.up8 = nn.ConvTranspose2d(256, 128, 2, stride=2)
        self.conv8 = DoubleConv(256, 128)
        self.up9 = nn.ConvTranspose2d(128, 64, 2, stride=2)
        self.conv9 = DoubleConv(128, 64)
        self.conv10 = nn.Conv2d(64,out_ch, 1)
        self.sigmoid = nn.Sigmoid()
    
    def forward(self,x):
        c1=self.conv1(x)
    
        p1=self.down1(c1)
        c2=self.conv2(p1)
        p2=self.down2(c2)
        c3=self.conv3(p2)
        p3=self.down3(c3)
        c4=self.conv4(p3)
        p4=self.down4(c4)
        c5=self.conv5(p4)
        up_6= self.up6(c5)
        merge6 = torch.cat([up_6, c4], dim=1)
        c6=self.conv6(merge6)
        up_7=self.up7(c6)
        merge7 = torch.cat([up_7, c3], dim=1)
        c7=self.conv7(merge7)
        up_8=self.up8(c7)
        merge8 = torch.cat([up_8, c2], dim=1)
        c8=self.conv8(merge8)
        up_9=self.up9(c8)
        merge9=torch.cat([up_9,c1],dim=1)
        c9=self.conv9(merge9)
        c10=self.conv10(c9)
        out = self.sigmoid(c10)
        return out

    我又重新写了这样的,可以用.eval(),但是跑出来结果会比不用的差了大概十个点,这就有点懵逼了,而且我测试代码二分类。居然会有测出灰色的,我也是醉了。。。

  • 关于 pytorch 中.eval () 的问题 at 1个月前

    那请问一下出现这个问题应该怎么处理,或者不用model.eval()做出来的结果可以用吗。。。