Hi,
I’m trying to modify PixelCNN model to work on 1D as well.
Let’s say i want the input of the network to be vector (size 20) and output a vector (size 60), I tried to play with the architecture to make it work but it didnt work.
First of all i changed to Conv2D to be 1D (the mask work on 1D now). but i dont understand how to make it train.
this is the architecture of the model:
class PixelCNN(nn.Module):
def __init__(self, no_layers=8, kernel = 7, channels=64, device=None, e_dim=16, z_dim=64):
super(PixelCNN, self).__init__()
self.no_layers = no_layers
self.kernel = kernel
self.channels = channels
self.layers = {}
self.device = device
self.Conv2d_1 = MaskedCNN('A',1,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_1 = nn.BatchNorm2d(channels)
self.ReLU_1= nn.ReLU(True)
self.Conv2d_2 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_2 = nn.BatchNorm2d(channels)
self.ReLU_2= nn.ReLU(True)
self.Conv2d_3 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_3 = nn.BatchNorm2d(channels)
self.ReLU_3= nn.ReLU(True)
self.Conv2d_4 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_4 = nn.BatchNorm2d(channels)
self.ReLU_4 = nn.ReLU(True)
self.Conv2d_5 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_5 = nn.BatchNorm2d(channels)
self.ReLU_5= nn.ReLU(True)
self.Conv2d_6 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_6 = nn.BatchNorm2d(channels)
self.ReLU_6= nn.ReLU(True)
self.Conv2d_7 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_7 = nn.BatchNorm2d(channels)
self.ReLU_7= nn.ReLU(True)
self.Conv2d_8 = MaskedCNN('B',channels,channels, kernel, 1, kernel//2, bias=False)
self.BatchNorm2d_8 = nn.BatchNorm2d(channels)
self.ReLU_8= nn.ReLU(True)
self.out = nn.Conv2d(channels, 256, 1)
MaskedCNN defined as:
class MaskedCNN(nn.Conv2d):
def __init__(self, mask_type, *args, **kwargs):
self.mask_type = mask_type
assert mask_type in ['A', 'B'], "Unknown Mask Type"
super(MaskedCNN, self).__init__(*args, **kwargs)
self.register_buffer('mask', self.weight.data.clone())
_, depth, height, width = self.weight.size()
self.mask.fill_(1)
if mask_type =='A':
self.mask[:,:,height//2,width//2:] = 0
self.mask[:,:,height//2+1:,:] = 0
else:
self.mask[:,:,height//2,width//2+1:] = 0
self.mask[:,:,height//2+1:,:] = 0
def forward(self, x):
self.weight.data*=self.mask
return super(MaskedCNN, self).forward(x)
Thanks