Shalin Savalia
Shalin Savalia

Reputation: 35

reshape image error

im=Image.open("/Users/shalinsavalia/Desktop/CNN_Numbers/Number_7.jpg")
im
im=im.resize((28, 28), Image.ANTIALIAS) # resize the image
im = np.array(im)                       # convert to an array
print(im)
im2=im/np.max(im).astype(float)         # normalise input
test_image1=np.reshape(im2, [1,784])    # reshape it to our input placeholder shape

pred=(sess.run(y_predicted,
               feed_dict={
                   x:test_image1
               }))
predicted_class=np.argmax(pred)
print "Predicted class : {}" .format(predicted_class)

Error in result is:

Traceback (most recent call last):
  File "./CNN_Numbers.py", line 238, in <module>
    test_image1=np.reshape(im2, [1,784]) # reshape it to our input placeholder shape
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 257, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 52, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
ValueError: cannot reshape array of size 3136 into shape (1,784)

Upvotes: 0

Views: 2007

Answers (1)

Jus
Jus

Reputation: 521

I guess your image has 3+1 color channels. You need to reshape to [784, 4].

Upvotes: 1

Related Questions