java equalwith_Tensorflow Error: ValueError: Shapes must be equal rank, but are 2 and 1 From merging...

2017-02-15 17:01:40

1

I am trying to use tensorflow for implementing a dcgan and have run into this error:

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. 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:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值