张量流中的Feedholder形状不匹配

时间:2017-12-30 20:01:35

标签: python python-3.x numpy tensorflow scipy

我在输入和Feedholder之间的形状不匹配,即使我很确定两种情况下的形状是相同的。这是代码: ex3data1.mat包含一个5000 * 400矩阵X.

    import tensorflow as tf
    import numpy as np
   `import scipy.io as sio
    theta1 = sio.loadmat('ex3weights.mat')['Theta1']
    theta2 = sio.loadmat('ex3weights.mat')['Theta2']
    x = tf.placeholder(tf.float64, shape=[1, 400])
    x2 = tf.concat([[[1]] ,x], 1)
    z2 = tf.matmul(x2,np.transpose(theta1))
    h1 = tf.divide(1.0, (1.0 + tf.exp(-z1)))
    h1= tf.concat([[[1]],h1], 1)
    z2 = tf.matmul(h1, np.transpose(theta2))
    max = tf.argmax(z2)
    max = max+1 
    sess = tf.Session()
    op = sio.loadmat('ex3data1.mat')['X'][1234]
    op = np.reshape(op, [1, 400])
    op.astype(np.float64)
    m = {x:op}
    sess.run(max,feed_dict=m)

我收到以下错误:

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_2' with dtype double and shape [1,400]
     [[Node: Placeholder_2 = Placeholder[dtype=DT_DOUBLE, shape=[1,400], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

1 个答案:

答案 0 :(得分:0)

为什么不

print(op.shape)

在将dict分配给m之前?我想这是[5000,400]。当元素数量不变时,重塑可以工作。但是,如果您希望' input_width'宽流,您可以这样定义占位符:

x = tf.placeholder(tf.float64, [None, input_width], "network_input")

允许案件的数量灵活。然后你可以用任意数量的情况喂它,比如5000,数学仍然有用。