Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make single prediction #13

Closed
Wheele9 opened this issue Apr 6, 2016 · 4 comments
Closed

How to make single prediction #13

Wheele9 opened this issue Apr 6, 2016 · 4 comments

Comments

@Wheele9
Copy link

Wheele9 commented Apr 6, 2016

Hi

I am new to tensorflow, and I am stuck at your logistic_expression example.
I trained and saved the model, restored it, but I am unable to use it. Can you help me with that?
I tried:

print (sess.run(predict_op, feed_dict={X: teX[66], Y: teY[66]}))
I am expecting a 6 here as output (or a number at least :D) but I got an error:

ValueError: Cannot feed value of shape (784,) for Tensor 'Placeholder:0', which has shape '(?, 784)'

@Waateur
Copy link

Waateur commented Apr 7, 2016

Hello,
It's feels to me that you made predict_op using a batch input of size : ( None, 784 ) .
But the data in teX are(784,) . You should reshape them in order to be ( 1 , 784 ) .
You can use reshape for a numpy.ndarray or a list comprehension for a float list something like :
[ [x] for x in teX ]

Hope it helped.

@Wheele9
Copy link
Author

Wheele9 commented Apr 7, 2016

Hello
I guess I undestood the problem thanks! I solved it like that:

newtx=[ [x] for x in teX ]
newty=[[y] for y in teY]
print (sess.run(prediction, feed_dict={X: newtx[nr], Y: newty[nr]}))

Other question when I load an image from other sources, and reshape it like that. I will not have the label to it, but i have to still give a dummy item to Y right? Is there a more elegant solution? Something like: predicted_label=sess.run(prediction, feed_dict={X:img}) What is the role of Y in th sess.run when the training is done?

p.s

A faster solution is with the numpy, but reshape was not good for me, I had to add a dimension like that and it works now :

img  # shape  : (784,)
img=np.expand_dims(img, axis=0) # shape  : (1, 784)

@nlintz
Copy link
Owner

nlintz commented Apr 11, 2016

You can actually run the predict op without passing in Y:teY since Y isn't part of the predict_op graph. You can just run sess.run(predict_op, feed_dict={X: teX}))

@Wheele9
Copy link
Author

Wheele9 commented Apr 11, 2016

Yeah i figured that out, thanks!

@Wheele9 Wheele9 closed this as completed Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants