InvalidArgumentError设置或代码错误?

时间:2017-04-15 02:06:44

标签: python python-3.x tensorflow

我收到错误,InvalidArgumentError就像

一样
  

InvalidArgumentError(请参阅上面的回溯):您必须提供值   对于占位符张量' Placeholder_1'用dtype float [[节点:   Placeholder_1 = Placeholderdtype = DT_FLOAT,shape = [],   _device =" /作业:本地主机/复制:0 /任务:0 / CPU:0"]]

我无法理解我的代码中有什么问题。我无法理解错误的一点是设置或代码(语法)。

我该如何解决这个问题?

我在我的整个代码中写道

import tensorflow as tf
import numpy as np

input_dim =2
output_dim =1

x = tf.placeholder("float",[None,input_dim])
#重み
W = tf.Variable(tf.random_uniform([input_dim,output_dim],-1.0,1.0))
#バイアス
b = tf.Variable(tf.random_normal([output_dim]))
#シグモイド活性化調節
y = tf.nn.sigmoid(tf.matmul(x,W)+b)

y_ = tf.placeholder("float",[None,output_dim])
loss = tf.reduce_mean(tf.square(y-y_))
train_step = tf.train.MomentumOptimizer(0.01,0.97).minimize(loss)

init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)

for i in range(5000):
    batch_xs = np.array([
        [0.,0.],
        [0.,1.],
        [1.,0.],
        [1.,1.]
    ])
    batch_ys = np.array([
        [0.],
        [0.],
        [0.],
        [1.]
    ])
    sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})
    print(i,sess.run(y,feed_dict={x:batch_xs,y:batch_ys}))

1 个答案:

答案 0 :(得分:0)

您有占位符y_x,而不是ysess.run(

所以sess.run(train_step,feed_dict={x:batch_xs,y_:batch_ys}))应该是interp1