我試圖使用tensorflow用於實現dcgan並遇到了這個錯誤:Tensorflow錯誤:ValueError異常:形狀必須是同等級別,但2個和1個從合併形狀1與其他形狀
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].
據iv收集它表明我的張量形狀是不同的,但我不明白我需要改變,以解決這個錯誤。我相信,這個錯誤在這些方法之間的某處掛起:
首先,我使用創建的方法的佔位符:
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)
然後最後一條語句調用生成方法,該方法使用重塑通過改變張量:
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))
如果它幫助這裏是我的線性方法:
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
編輯:
我也使用這些佔位符:
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
乾杯!成功了! – Volken