我正在尝试实现cDCGAN。我的数据集有2350个num_classes,batch_size是100,图像大小是64(行= 64,cols = 64,channels = 1),z_shape是100。值的占位符如下。
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))
我正在如下所示的训练循环中为phY_g和phY_d加载一批图像,noise_Z和标签(一个热编码)。
# 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])
一切正常,但对于batch_Y_d,我收到错误消息“ ValueError:无法将大小为235000的数组重塑为形状(100,64,64,2350)”
如何根据占位符形状重塑形状?
答案 0 :(得分:0)
在cDCGAN中,您不应更改self.phY_d
,而需要更改batch_Y_d
。
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)