ValueError:无法将235000尺寸的阵列重塑为形状(100,64,64,2350)



我正在尝试实现cdcgan。我的数据集有2350个num_classes,batch_size为100,图像大小为64(行= 64,cols = 64,channel = 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加载一批图像,noings_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,64,2350)"

如何根据占位符形状重塑它?

您不应该更改self.phY_d,并且需要更改batch_Y_d如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)

相关内容

  • 没有找到相关文章

最新更新