先贴网络吧
我所用的One-class数据和网络如下:
#以256*64的数据为例子,grid为4,batch为4。
#在训练网络权重时,数据经过每一层后的维度如下:
torch.Size([4, 3, 64, 256])
torch.Size([4, 48, 32, 128])
torch.Size([4, 96, 33, 64])
torch.Size([4, 96, 33, 64])
torch.Size([4, 96, 33, 64])
torch.Size([4, 192, 34, 32])
torch.Size([4, 192, 34, 32])
torch.Size([4, 192, 34, 32])
torch.Size([4, 384, 17, 16])
torch.Size([4, 384, 17, 16])
torch.Size([4, 384, 17, 16])
torch.Size([4, 768, 8, 8])
torch.Size([4, 768, 8, 8])
torch.Size([4, 768, 8, 8])
torch.Size([4, 1536, 4, 4])
torch.Size([4, 1536, 4, 4])
torch.Size([4, 1536, 4, 4])
torch.Size([4, 768, 8, 8])
torch.Size([4, 768, 8, 8])
torch.Size([4, 768, 8, 8])
torch.Size([4, 384, 8, 16])
torch.Size([4, 384, 8, 16])
torch.Size([4, 192, 8, 32])
torch.Size([4, 192, 8, 32])
torch.Size([4, 96, 16, 64])
torch.Size([4, 96, 16, 64])
torch.Size([4, 48, 32, 128])
torch.Size([4, 48, 32, 128])
torch.Size([4, 3, 64, 256])
torch.Size([4, 3, 64, 256])
#网络如下:
NetG(
(encoder): Encoder(
(main): Sequential(
(initial-conv-3-48): Conv2d(3, 48, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(initial-relu-48): LeakyReLU(negative_slope=0.2, inplace)
(pyramid-48-96-conv): Conv2d(48, 96, kernel_size=(4, 4), stride=(1, 2), padding=(2, 1), bias=False)
(pyramid-96-batchnorm): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(pyramid-96-relu): LeakyReLU(negative_slope=0.2, inplace)
(pyramid-96-192-conv): Conv2d(96, 192, kernel_size=(4, 4), stride=(1, 2), padding=(2, 1), bias=False)
(pyramid-192-batchnorm): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(pyramid-192-relu): LeakyReLU(negative_slope=0.2, inplace)
(pyramid-192-384-conv): Conv2d(192, 384, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(pyramid-384-batchnorm): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(pyramid-384-relu): LeakyReLU(negative_slope=0.2, inplace)
(pyramid-384-768-conv): Conv2d(384, 768, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(pyramid-768-batchnorm): BatchNorm2d(768, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(pyramid-768-relu): LeakyReLU(negative_slope=0.2, inplace)
(pyramid-768-1536-conv): Conv2d(768, 1536, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(pyramid-1536-batchnorm): BatchNorm2d(1536, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(pyramid-1536-relu): LeakyReLU(negative_slope=0.2, inplace)
)
)
(decoder): Decoder(
(main): Sequential(
(initial-1536-768-convt): ConvTranspose2d(1536, 768, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(initial-768-batchnorm): BatchNorm2d(768, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(initial-768-relu): ReLU(inplace)
(pyramid-768-384-convt): ConvTranspose2d(768, 384, kernel_size=(3, 4), stride=(1, 2), padding=(1, 1), bias=False)
(pyramid-384-relu): ReLU(inplace)
(pyramid-384-192-convt): ConvTranspose2d(384, 192, kernel_size=(3, 4), stride=(1, 2), padding=(1, 1), bias=False)
(pyramid-192-relu): ReLU(inplace)
(pyramid-192-96-convt): ConvTranspose2d(192, 96, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(pyramid-96-relu): ReLU(inplace)
(pyramid-96-48-convt): ConvTranspose2d(96, 48, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(pyramid-48-relu): ReLU(inplace)
(final-48-3-convt): ConvTranspose2d(48, 3, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
(final-3-sigmoid): Sigmoid()
)
)
)
然后,网络所以的三个函数:
1.优化函数:adam+动量
self.optimizer_g = optim.Adam(self.netg.parameters(), lr=self.opt.lr, betas=(self.opt.beta1, 0.999))
2.损失函数:L2loss。
def l2_loss(self, input, target, size_average=True):
if size_average:
return torch.mean(torch.pow((input-target), 2))
else:
return torch.pow((input-target), 2)
3.激活函数:激活函数是线性Relu和非线性Relu