gpt4 book ai didi

python - 值错误 : cannot reshape array of size 235000 into shape (100, 64,64,2350)

转载 作者:行者123 更新时间:2023-11-28 18:58:55 26 4
gpt4 key购买 nike

我正在尝试实现 cDCGAN。我的数据集有 2350 个 num_classes,batch_size 是 100,图像大小是 64(rows=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 的数组 reshape 为形状 (100,64,64,2350)”

我怎样才能根据我的占位符形状 reshape 它?

最佳答案

你不应该改变 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)

关于python - 值错误 : cannot reshape array of size 235000 into shape (100, 64,64,2350),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55048373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com