Hi Ptrblck,
I am trying to add extra layer like Resnet, to the input layer and then pass it to the next layer. (not exact as Resnet, by adding conv3d (self.l33 and self.l44) between my generator layers, I want to add more features to the generator)
Should I use "Conv3d or Conv1d " in the last layer (self.l6). I think Cond3d is correct. Can I write the last layer with Conv1d?
ngpu=1
nz=11
ngf=8
class Generator(nn.Module):
def __init__(self,ngpu,nz,ngf):
super(Generator, self).__init__()
self.ngpu=ngpu
self.nz=nz
self.ngf=ngf
## ---1x11x1x1x1
self.l1= nn.Sequential(
nn.ConvTranspose3d(self.nz+1, self.ngf * 6, 3, 1, 0, bias=True),
nn.BatchNorm3d(self.ngf * 6),
nn.ReLU(),)
##---48x3x3x3
self.l2=nn.Sequential(nn.ConvTranspose3d(self.ngf * 6, self.ngf * 4, 3, 2, 0, bias=True),
nn.BatchNorm3d(self.ngf * 4),
nn.ReLU(),)
## ---32x7x7x7
self.l3=nn.Sequential(nn.ConvTranspose3d( self.ngf * 4, self.ngf * 2, 3, 1, 0, bias=True),
nn.BatchNorm3d(self.ngf * 2),
nn.ReLU(),)
## ----16x9x9x9
self.l4=nn.Sequential(nn.ConvTranspose3d( self.ngf*2, self.ngf*2, 3, 1, 0, bias=True),nn.BatchNorm3d(self.ngf * 2),
nn.ReLU(),)
## ----16x9x9x9
self.l44=nn.Sequential(nn.Conv3d(ngf * 2, self.ngf * 2, 3, 1, 1, bias=True),nn.BatchNorm3d(ngf * 2),nn.ReLU())
## ---16x11x11x11
self.l5=nn.Sequential(nn.ConvTranspose3d( self.ngf*2, self.ngf*2, 3, 1, 0, bias=True),nn.BatchNorm3d(self.ngf * 2),
nn.ReLU(),)
## ---16x11x11x11
self.l55=nn.Sequential(nn.Conv3d(ngf * 2, self.ngf*2, 3, 1, 1, bias=True),nn.BatchNorm3d(ngf * 2),nn.ReLU())
## ---1x11x11x11
self.l6=nn.Sequential(nn.Conv3d( self.ngf*2, 1, 3, 1, 0, bias=True),nn.Sigmoid())
def forward(self, input,Labels):
Labels=Labels.unsqueeze(1).unsqueeze(2).unsqueeze(3).unsqueeze(4)
InputCat=torch.cat((Labels,input),1)
out1=self.l1(InputCat)
out2=self.l2(out1)
out3=self.l3(out2)
out4=self.l4(out3)
out5=self.l44(out4)
## ---- add layers---
out6=out5+out4
out7=self.l5(out6)
out8=self.l55(out7)
## ---- add layers---
out9=out8+out7
out_total=self.l6(out9)
return out_total
batchsize=10
Noise=torch.randn(batchsize,nz,1,1,1)
Condition=torch.ones(size=(batchsize,))
Gen=Generator(ngpu,nz,ngf)
Out=Gen(Noise,Condition)