Tensorflow: Vous devez fournir une valeur pour l'espace réservé tenseur 'Placeholder' avec dtype float [mais la valeur est un float]

Je vais dans une tensorflow tutoriel et reçois cette erreur:

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

Ici est le traceback:

Traceback (most recent call last):
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 972, in _do_call
return fn(*args)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 954, in _run_fn
status, run_metadata)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/contextlib.py", line 66, in __exit__
next(self.gen)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/framework/errors.py", line 463, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "neural_network.py", line 48, in <module>
print(sess.run(loss), feed_dict={xs:x_data, ys:y_data})
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 717, in run
run_metadata_ptr)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 915, in _run
feed_dict_string, options, run_metadata)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 965, in _do_run
target_list, options, run_metadata)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 985, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'Placeholder', defined at:
File "neural_network.py", line 21, in <module>
xs = tf.placeholder(tf.float32,[None,1])
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1332, in placeholder
name=name)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1748, in _placeholder
name=name)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
op_def=op_def)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2380, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/mddrill/anaconda2/envs/python35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1298, in __init__
self._traceback = _extract_stack()

Voici mon code:

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def add_layer(inputs, in_size, out_size,activation_function=None):
Weights = tf.Variable(tf.random_normal([in_size, out_size]))
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs
# Make up some data
x_data = np.linspace(-1,1,300, dtype=np.float32)[:,np.newaxis]
noise = np.random.normal(0,0.05,x_data.shape).astype(np.float32)
y_data = np.square(x_data) - 0.5 + noise
# define placeholder for inputs to network
xs = tf.placeholder(tf.float32,[None,1])
ys = tf.placeholder(tf.float32,[None,1])
# add hidden layer
lay1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu)
#add output layer
prediction = add_layer(lay1, 10, 1, activation_function=None)
# the error between prediction and real data
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction), reduction_indices=[1]))
### if we have [[3,4],[5,6],[7,8]] and reduction_indices is 1
### then we are taking f(3,4) f(5,6) and f(7,8)
### if reduction_indices is 0, then we are taking
### f(3,5,7) and f(4,6,8)
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
# important step
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for i in range(1000):
# training
sess.run(train_step, feed_dict={xs:x_data, ys:y_data})
if i% 50 == 0:
# to see the step improvement
print(sess.run(loss), feed_dict={xs:x_data, ys:y_data})

Comme vous pouvez le voir ici, à la fois x_data et y_data sont les chars, donc je ne comprends pas pourquoi j'obtiens cette erreur.

Quand j'ajoute une instruction print print(type(x_data[0][0]),type(y_data[0][0])) juste avant sess.run(train_step, feed_dict={xs:x_data, ys:y_data}). J'obtiens ceci: <class 'numpy.float32'> <class 'numpy.float32'> Donc clairement qu'ils sont les deux flotteurs

Ce qui me manque ici?

Utilisez-vous TensorFlow r0.12?

OriginalL'auteur Matt D | 2017-01-01