Hi, I am trying to reproduce some Generator for a GAN based on the code from this repo (they use tensor flow) InfoGAN/model.py at master · lisc55/InfoGAN · GitHub
at some point I get the error of mismatching dimensionalities(the error itself is below). I would appreciate any help explaining what I did wrong. Thanks in advance
here is my model:
class Generator(nn.Module):
def __init__(self):
super(Generator, self).__init__()
# opt.latent_dim = 62; opt.n_classes = 5
input_dim = opt.latent_dim + opt.n_classes # is equal to 67
self.l1 = nn.Sequential(nn.Linear(input_dim, 1024, bias=False))
self.conv_blocks = nn.Sequential(
nn.BatchNorm2d(1024),
nn.ReLU(True),
nn.Linear(1024, 7*7*128, bias=False),
nn.BatchNorm2d(7*7*128),
nn.ReLU(True),
#nn.Unflatten(7*7*128, [-1, 7, 7, 128]),
nn.ConvTranspose2d(7*7*128, 64, (4, 4), 2, 1),
nn.BatchNorm2d(64),
nn.ReLU(True),
nn.ConvTranspose2d(7*7*128, 1, (4, 4), 2, 1),
nn.Tanh()
)
def forward(self, noise, labels):
# batch_size is 64
# noise shape is (64, 62); labels shape is (64, 5)
gen_input = torch.cat((noise, labels), -1) # shape is (64, 67)
out = self.l1(gen_input) # shape is (64, 1024)
out = out.view(out.shape[0], 1024, 1, 1) # shape is (64, 1024, 1, 1)
img = self.conv_blocks(out) # <- error appears here
return img
the error I get is: RuntimeError: mat1 and mat2 shapes cannot be multiplied (65536x1 and 1024x6272)
Original code using tf is:
def Generator(shape):
w_init = tf.random_normal_initializer(stddev=0.02)
gamma_init = tf.random_normal_initializer(1.0, 0.02)
ni = tl.layers.Input(shape)
nn = tl.layers.Dense(n_units=1024, b_init=None, W_init=w_init)(ni)
nn = tl.layers.BatchNorm(decay=0.9, act=tf.nn.relu,
gamma_init=gamma_init)(nn)
nn = tl.layers.Dense(n_units=7*7*128, b_init=None, W_init=w_init)(nn)
nn = tl.layers.BatchNorm(decay=0.9, act=tf.nn.relu,
gamma_init=gamma_init)(nn)
nn = tl.layers.Reshape([-1, 7, 7, 128])(nn)
nn = tl.layers.DeConv2d(64, (4, 4), strides=(
2, 2), padding="SAME", W_init=w_init)(nn)
nn = tl.layers.BatchNorm(decay=0.9, act=tf.nn.relu,
gamma_init=gamma_init)(nn)
nn = tl.layers.DeConv2d(
1, (4, 4), strides=(2, 2), padding="SAME", act=tf.nn.tanh, W_init=w_init)(nn)
return tl.models.Model(inputs=ni, outputs=nn)