Tensorflow.python.framework.errors_impl. Invalidargumenterror:you must feed a value for placeholder tensor ' x_1 ' with dtype float and shape [?, 227,227,3]

Source: Internet
Author: User

Remember the super stupid super-torture my bug.

Error content:

Tensorflow.python.framework.errors_impl. Invalidargumenterror:you must feed a value for placeholder tensor ' x_1 ' with dtype float and shape [?, 227,227,3]
[[node:x_1 = Placeholder[dtype=dt_float, shape=[?,227,227,3], _device= "/job:localhost/replica:0/task:0/device:gpu : 0 "] ()]
[[node:fc3/_33 = _recv[client_terminated=false, recv_device= "/job:localhost/replica:0/task:0/device:cpu:0", Send_ Device= "/job:localhost/replica:0/task:0/device:gpu:0", Send_device_incarnation=1, Tensor_name= "EDGE_110_FC3", Tensor_type=dt_float, _device= "/job:localhost/replica:0/task:0/device:cpu:0"] ()]

The error is simple to understand and does not give placeholder ' x_1 ' assignment.

Here is my forecast code:

Image = Image.open (imagefile)
Image = Image.resize ([227, 227])
Image_array = Np.array (image)
Image_array = Image_array.astype (float)
Image = Np.reshape (Image_array, [1, 227, 227, 3])
Saver = tf.train.import_meta_graph ("/home/ubuntu/demo/package/5.8_2000op_256batch/alexnetmodel.ckpt.meta")
Graph = Tf.get_default_graph ()
Prediction = Graph.get_tensor_by_name ("fc3:0")
x = Graph.get_tensor_by_name ("x:0")
With TF. Session () as Sess:
Saver.restore (Sess, "/home/ubuntu/demo/package/5.8_2000op_256batch/alexnetmodel.ckpt")
Predict = Sess.run (prediction, Feed_dict={x:image})
Max_index = Np.argmax (Predict)
If max_index==0:
Return "Cat"
Else
Return "Dog"

Previously, there was a problem with the image format and could not be entered as input to X.

Because the most original, the source code is written like this:

Image = Image.open (imagefile)
Image = Image.resize ([227, 227])
Image_array = Np.array (image)

Image = Tf.cast (image_array,tf.float32)
Image = Tf.image.per_image_standardization (image)
Image = Tf.reshape (image, [1, 227, 227, 3])

Instead of using the TF method, the return value is a tensor, and tensor is a data type that cannot be assigned to a placeholder definition.

    • Sess.run () The first parameter is the variable to fetch, the type of the variable can only be tensor or string, if you want to add feed_dict = {} , note that the data type of the feed can be Python scalars, strings, lists, NumPy Ndarrays, or tensorhandles, cannot be tensor.fecth to get the variable is <type ‘numpy.ndarray‘> . The bottom line is that when you run the diagram, the tensor is sess.run() taken out and then feeds in.

So the shape of the image changes, Tf.reshape () changed to Np.reshape (), but there is a problem, error for the above you must feed a value for placeholder tensor ' x_1 ' with Dtype Flo At and shape [?, 227,227,3] ....

Finished completely put me whole, do not know what kind of input to x, but it is very strange, placeholder tensor ' x_1 ' there, has not defined ' x_1 ' this kind of thing ah. Post the training code, placeholder the application.

x = Tf.placeholder (Tf.float32, [None, 227, 227, 3],name= ' x ')
y = Tf.placeholder (Tf.float32, [None, n_classes])

The feeling is ok ah, very good ah. If the code really does not have a problem really good, the key is their brain residue, x = Tf.placeholder (Tf.float32, [None, 227, 227, 3],name= ' x ') applied two times

Remove one. It's OK. Very annoying, troubled myself for several days

Tensorflow.python.framework.errors_impl. Invalidargumenterror:you must feed a value for placeholder tensor ' x_1 ' with dtype float and shape [?, 227,227,3]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.