Tensorflow ValueError:Cannot feed value of shape (40, 24, 24, 4) for Tensor u'real_images:0', which has shape '(40, 24, 24, 3)'
Tensorflow ValueError:Cannot feed value of shape (40, 24, 24, 4) for Tensor u'real_images:0', which has shape '(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)
# discriminator
_,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 图像。
尝试实现 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)
# discriminator
_,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 图像。