3

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 ?

Ammar Ul Hassan
  • 826
  • 1
  • 18
  • 48
  • The shape of `batch_Y_d` is `(100,2350)` equal to `train_labels`. It can't reshape to `(100,64,64,2350)`. – giser_yugang Mar 08 '19 at 02:12
  • @giser_yugang So what should i manipulate to make it work. Do i need to change my placeholder shape ? – Ammar Ul Hassan Mar 08 '19 at 02:19
  • I don't know what the use of `self.phY_d` is. If you have to feed `batch_Y_d`, you need to change it. – giser_yugang Mar 08 '19 at 02:25
  • @giser_yugang self.phY_d placeholder takes batch of values of labels for my discriminator. And in Discriminator function it uses tf.concat() to combine the the real image batch (self.phX) and (self.phY_d). – Ammar Ul Hassan Mar 08 '19 at 02:30

1 Answers1

0

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)
giser_yugang
  • 6,058
  • 4
  • 21
  • 44