feed_dict的参数错误

时间:2017-04-12 00:23:15

标签: python tensorflow neural-network deep-learning conv-neural-network

我对feed_dict感到困惑。我可以将数据集作为X提供,但我无法提供Y标签。所有的dtype都是tf.float64,我将它打印出来,是的,它们是float64。我的X数据集的形状为90,32,32,3,我的Y为90,2。所以我定义了一个plaeholder被喂养相同的形状。

但是当我运行我的代码时,出现了错误:

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

我不知道为什么会这样,因为我确信X和Y都是float64。 X很好,但为什么只有Y?请帮助,我真的很感激:))

这是代码:

size_image =32
allX = np.zeros((100, size_image, size_image, 3), dtype='float64')
ally = np.zeros(100, dtype='float64')
count = 0
for i in range(49):
    img = io.imread("cat/cat"+str(i+1)+".jpg")
    new_img = imresize(img, (size_image, size_image, 3))
    allX[count] = np.array(new_img)
    ally[count] = 0
    count += 1

#dog images and labels
for i in range(51):
        img = io.imread("dog/dog"+str(i+1)+".jpg")
        new_img = imresize(img, (size_image, size_image, 3))
        allX[count] = np.array(new_img)
        ally[count] = 1
        count += 1

#splitting dataset supaya random
X, X_test, Y, Y_test = train_test_split(allX, ally, test_size=0.1, random_state=42)

# encode the Ys
Y = to_categorical(Y, 2)
Y_test = to_categorical(Y_test, 2)

x = tf.placeholder(tf.float64, [None,None, None,3])
y_ = tf.placeholder(tf.float64, [None, 2])

sess = tf.Session()
sess.run(init)
t = x*2
print(sess.run(t, feed_dict={x:X}))

m = 1*y
print(sess.run(m, feed_dict={y_:Y}))

这是追溯:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-95-6f97fe1da9c0> in <module>()
      6 print(y.get_shape())
      7 m = 1*y
----> 8 print(sess.run(m, feed_dict={y_:Y}))
      9 print(y_.get_shape().as_list())
     10 #x = tf.stack(X)

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

Caused by op u'Placeholder_34', defined at:
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelapp.py", line 474, in start
    ioloop.IOLoop.instance().start()
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 887, in start
    handler_func(fd_obj, events)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 276, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 390, in execute_request
    user_expressions, allow_stdin)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/zmqshell.py", line 501, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2717, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2821, in run_ast_nodes
    if self.run_code(code, result):
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-94-297273a8e189>", line 1, in <module>
    x = tf.placeholder(tf.float64, [None,None, None,3])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1520, in placeholder
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 2149, in _placeholder
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2395, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1264, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_34' with dtype double
     [[Node: Placeholder_34 = Placeholder[dtype=DT_DOUBLE, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

0 个答案:

没有答案