I am trying to implement a cDCGAN. My dataset has 2350 num_classes, batch_size is 100, image size is 64 (rows=64, cols=64, channels=1), z_shape is 100 My placeholders for values are as follows.
self.phX = tf.placeholder(tf.float32, [None, self.rows, self.cols, self.channels])
self.phZ = tf.placeholder(tf.float32, [None, self.z_shape])
self.phY_g = tf.placeholder(tf.float32, [None, self.num_classes])
self.phY_d = tf.placeholder(tf.float32, shape=(None, self.rows, self.cols, self.num_classes))
I am loading batch of images, noise_Z and labels(one hot encoded) for both phY_g and phY_d in training loop as below.
# Get a random batch of images and labels. This gives 100 images of shape [100,4096] and 100 labels of shape [100,2350]
train_images, train_labels = self.sess.run([self.image_batch, self.label_batch])
# Real image input for Real Discriminator,
# Reshape images to pass to D
batch_X = train_images.reshape((self.batch_size, self.rows, self.cols, self.channels))
batch_X = batch_X * 2 - 1
# Z noise for Generator
batch_Z = np.random.uniform(-1, 1, (self.batch_size, self.z_shape)) # Shape is [?, 100]
# Label input for Generator
batch_Y_g = train_labels
batch_Y_g = batch_Y_g.reshape([self.batch_size, self.num_classes])
# Label input for Discriminator
batch_Y_d = train_labels
batch_Y_d = batch_Y_d.reshape([self.batch_size, self.rows, self.cols, self.num_classes])
Everything works well but for batch_Y_d i get error "ValueError: cannot reshape array of size 235000 into shape (100,64,64,2350)"
How can i reshape it according to my placeholder shape ?
You should not to change self.phY_d
and you need to change batch_Y_d
as follow in cDCGAN.
batch_Y_d = train_labels
batch_Y_d = batch_Y_d.reshape([self.batch_size,1,1,self.num_classes])
batch_Y_d = batch_Y_d * np.ones([batch_size, self.rows, self.cols, self.num_classes])
print(batch_Y_d.shape)
(100, 64, 64, 2350)