Tensorflow ValueError:无法为形状为(40, 24, 24, 4)的值馈送到张量’real_images:0’,其形状为'(40, 24, 24, 3)’

在尝试实现DCGAN时,在使用我的训练函数时收到了这个错误消息:

ValueError: Cannot feed value of shape (40, 24, 24, 4) for Tensor u'real_images:0', which has shape '(40, 24, 24, 3)'

这个错误发生在使用以下这行代码时:

_,summary_str = self.sess.run([dis_optim, self.dis_sum],feed_dict = {self.inputs: batch_images, self.z: batch_z})

关于为什么张量形状不同,有什么想法吗?下面我附上了我认为错误所在的代码:

real_images占位符(self.colour_dim是3):

image_dimension = [self.input_H,self.input_H, self.colour_dim]self.inputs = tf.placeholder(tf.float32, shape=[self.batch_size] + image_dimension, name='real_images')

错误发生的代码段:

for idx in xrange(0, batch_idxs):    batch_files = data[idx * config.batch_size:(idx +1) * config.batch_size]    batch = [getImage(batch_file,resize_h=self.output_H,resize_w=self.output_W) for batch_file in batch_files]    batch_images = np.array(batch).astype(np.float32)    print(batch_images)    batch_z = np.random.uniform(-1, 1, [config.batch_size, self.z_dimension]).astype(np.float32)    # 判别器    _,summary_str = self.sess.run([dis_optim, self.dis_sum],feed_dict = {self.inputs: batch_images, self.z: batch_z})    self.writer.add_summary(summary_str, counter)

使用的getImage和imread函数:

def imread(path):    return scipy.misc.imread(path).astype(np.float)def getImage(im_path, resize_h, resize_w):  image = imread(im_path)  return transform(image, resize_h, resize_w)

谢谢大家!


回答:

看起来你的图像加载函数返回的是RGBA图像,而网络期望的是RGB图像。在feed_dict中将batch_images替换为batch_images[:,:,:,:3]应该是一个简单的临时解决方案,你也可以查看你的加载函数是否支持直接返回RGB图像。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注