简体   繁体   English

Tensorflow错误:ValueError:形状必须等于等级,但是2和1从形状1与其他形状合并

[英]Tensorflow Error: ValueError: Shapes must be equal rank, but are 2 and 1 From merging shape 1 with other shapes

I am trying to use tensorflow for implementing a dcgan and have run into this error: 我试图使用tensorflow来实现dcgan并遇到这个错误:

ValueError: Shapes must be equal rank, but are 2 and 1
From merging shape 1 with other shapes. for 'generator/Reshape/packed' (op: 'Pack') with input shapes: [?,2048], [100,2048], [2048].

As far as iv gathered it indicates that my tensor shapes are different, but i cannot see what i need to change in order to fix this error. 就iv聚集而言,它表明我的张量形状是不同的,但我无法看到我需要改变以修复此错误。 I believe the mistake hangs somewhere in between these methods: 我相信错误在这些方法之间悬而未决:

First i create a placeholder in a method using: 首先,我使用以下方法在方法中创建占位符:

self.z = tf.placeholder(tf.float32, [None,self.z_dimension], name='z')
self.z_sum = tf.histogram_summary("z", self.z)

self.G = self.generator(self.z)

Then the last statement calls the generator method, this method uses reshape to change the tensor via: 然后最后一个语句调用生成器方法,此方法使用reshape通过以下方式更改张量:

 self.z_ = linear(z,self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=True)

 self.h0 = tf.reshape(self.z_,[-1, sample_H16, sample_W16,self.gen_dimension * 8])

 h0 = tf.nn.relu(self.gen_batchnorm1(self.h0))

If it helps here is my linear method: 如果它有帮助,这是我的线性方法:

def linear(input_, output_size, scope=None, stddev=0.02, bias_start=0.0, with_w=False):
shape = input_.get_shape().as_list()

with tf.variable_scope(scope or "Linear"):
  matrix = tf.get_variable("Matrix", [shape[1], output_size], tf.float32,tf.random_normal_initializer(stddev=stddev))
  bias = tf.get_variable("bias", [output_size],initializer=tf.constant_initializer(bias_start))
  if with_w:
    return tf.matmul(input_, matrix) + bias, matrix, bias
  else:
    return tf.matmul(input_, matrix) + bias

EDIT: 编辑:

I also use these placeholders: 我也使用这些占位符:

    self.inputs = tf.placeholder(tf.float32, shape=[self.batch_size] + image_dimension, name='real_images')
    self.gen_inputs = tf.placeholder(tf.float32, shape=[self.sample_size] + image_dimension, name='sample_inputs')
    inputs = self.inputs
    sample_inputs = self.gen_inputs

linear(z, self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=True) would be return the tuple (tf.matmul(input_, matrix) + bias, matrix, bias) . linear(z, self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=True)将返回元组(tf.matmul(input_, matrix) + bias, matrix, bias)

Therefore, self.z_ is assigned by the tuple, not the only one tf tensor. 因此, self.z_由元组赋值,而不是唯一的tf张量。

Just change linear(z, self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=True) to linear(z, self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=False) . 只需将linear(z, self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=True)更改为linear(z, self.gen_dimension * 8 * sample_H16 * sample_W16, 'gen_h0_lin', with_w=False)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError: Shapes must be equal rank, but are 1 and 0 从将形状 1 与其他形状合并。 对于“损失/添加” - ValueError: Shapes must be equal rank, but are 1 and 0 From merging shape 1 with other shapes. for 'loss/AddN' Tensorflow LSTM错误(ValueError:形状必须等于等级,但为2和1) - Tensorflow LSTM Error (ValueError: Shapes must be equal rank, but are 2 and 1 ) Keras LSTM TensorFlow错误:“形状必须等于等级,但必须为1和0” - Keras LSTM TensorFlow Error: 'Shapes must be equal rank, but are 1 and 0' Tensorflow-ValueError:形状必须为0级,但输入范围为[],[10],[]的“范围”(操作数:“范围”)的“极限”必须为1级 - Tensorflow - ValueError: Shape must be rank 0 but is rank 1 for 'limit' for 'range' (op: 'Range') with input shapes: [], [10], [] 形状必须相等 - Shapes must be equal rank tensorflow ValueError:两个形状的尺寸0必须相等 - tensorflow ValueError: Dimension 0 in both shapes must be equal ValueError:形状必须为 0 级,但对于“ReadFile”(操作:“ReadFile”)为 1 级,输入形状为:[1] - ValueError: Shape must be rank 0 but is rank 1 for 'ReadFile' (op: 'ReadFile') with input shapes: [1] tf.gradients: ValueError: Shapes must be equal rank, but are 2 and 1 - tf.gradients: ValueError: Shapes must be equal rank, but are 2 and 1 tensor_scatter_nd_update ValueError: Shapes must be equal rank, but are 0 and 1 - tensor_scatter_nd_update ValueError: Shapes must be equal rank, but are 0 and 1 Tensorflow:形状必须等于等级,但对于tf.norm来说形状必须为4和1, - Tensorflow : Shapes must be equal rank, but are 4 and 1, for tf.norm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM