Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

python - Tensorflow error using my own data

I've been playing with the Tensorflow library doing the tutorials. Now I wanted to play with my own data, but I fail horribly. This is perhaps a noob question but I can't figure it out.

I'm using this example: https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3%20-%20Neural%20Networks/convolutional_network.py

I want to use my own images, for converting my images to use with tensorflow i'm using this: https://github.com/HamedMP/ImageFlow/blob/master/ImageFlow.py

Now I change the parameters in the example from this:

 n_input = 784
 n_classes = 10

to this:

 n_input = 9216
 n_classes = 2

I did that because my images are 96 * 96 and there are only 2 classes of my images

I also change the weights and biases to the numbers I need.

I read the data like this:

batch_xs = imgReader.read_images(pathname);

imgReader being the ImageFlow file

but when I try to run it I gives me an error:

 ValueError: Cannot feed value of shape (104, 96, 96, 1) for Tensor
 u'Placeholder:0', which has shape (Dimension(None), Dimension(9216))

I feel like i'm overlooking something small but I don't see it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This error arises because the shape of the data that you're trying to feed (104 x 96 x 96 x 1) does not match the shape of the input placeholder (batch_size x 9216, where batch_size may be variable).

To make it work, add the following line before running a training step:

batch_xs = np.reshape(batch_xs, (-1, 9216))

This uses numpy to reshape the images read in, which are 4-D arrays of batch_size x h x w x channels, into a batch_size x 9216 element matrix as expected by the placeholder.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...