DP-GAN-判别器代码

在这里插入图片描述
将输出的rgb作为输入,输入到判别器中。接着执行一个for循环,看一下body_down列表的组成和x经过body_down之后的值。
在这里插入图片描述
在这里插入图片描述
body_down是由残差块D组成的列表:
在这里插入图片描述
残差块的参数为:(3,128),(128,128),(128,256),(256,256),(256,512),(512,512)/-1,根据i==0,判断first参数的True或者False。
在这里插入图片描述
残差块组成:
在这里插入图片描述
x首先进过shortcut。假设执行第一次for循环,通道(3,128)/-1/True.
在这里插入图片描述
将RGB下采样两倍。
在这里插入图片描述
接着in=3,out=128,learned_shortcut=True。
在这里插入图片描述
x再经过一个卷积:
在这里插入图片描述
接着输出x。执行完shortcut再执行卷积:
在这里插入图片描述
在这里插入图片描述
conv1输出一个mid_layer,conv2输出最终的out.
因为x在开始进行了下采样,为了能够相加,这里也对dx进下采样。
在这里插入图片描述
接着执行第二个块,输入和输出通道都是128.只执行下采样两倍。
在这里插入图片描述
后面的四个根据通道是否相等只执行如下操作:
在这里插入图片描述
这样encoder_res里面有六个值,将第四层和第六层输出放在dis_list中:
在这里插入图片描述
接着取出dis_list进行处理:
在这里插入图片描述
self.dis列表里面存放了两个nn.Sequential,分别处理dis_list的第一第二个。

        self.dis = nn.ModuleList([
                    nn.Sequential(
                            nn.Conv2d(256, 64, 3, padding=1, stride=2),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 64, 3, padding=1),
                            nn.BatchNorm2d(64),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 64, 3, padding=1),
                            nn.BatchNorm2d(64),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 64, 3, padding=1),
                            nn.BatchNorm2d(64),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 1, 3, padding=1)
                        ),
                    nn.Sequential(
                            nn.Conv2d(512, 64, 3, padding=1, stride=2),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 64, 3, padding=1),
                            nn.BatchNorm2d(64),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 64, 3, padding=1),
                            nn.BatchNorm2d(64),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 64, 3, padding=1),
                            nn.BatchNorm2d(64),
                            nn.LeakyReLU(0.2, False),
                            nn.Conv2d(64, 1, 3, padding=1)
                        )
            ])

在Sequential内部,首先将输入下采样两倍,然后三个卷积进行特征提取操作,最后卷积输除通道为1,输出Fake 或者real的概率。对应于:
在这里插入图片描述
接着将encoder最后一个输出作为decoder输入进行上采样:
在这里插入图片描述
残差块参数为:(512,512)/1,将输入上采样两倍。
在这里插入图片描述
剩下的五次卷积,分别倒着取列表里面的通道:
在这里插入图片描述
在这里插入图片描述
将decoder的值和encoder拼接,上采样6次,添加到return_feats列表中。
将最后一层输出值进过一个卷积,输出通道为类别通道数:
在这里插入图片描述
在这里插入图片描述
最后将最后一层输出值,encoder两个中间变量值,decoder的5个上采样中间值作为输出。

猜你喜欢

转载自blog.csdn.net/qq_43733107/article/details/132034156
GAN
今日推荐