Jump to content

Python/ Expected axis -1 of input shape to have value 3 but received input with shape (None, 32, 32, 1)

Zuccers
Go to solution Solved by igormp,
On 1/7/2021 at 7:36 AM, Zuccers said:

 

Hello, I made an image recognition model in python using keras, this is the input shape: 


input_shape=(3, 32, 32)

The model itself works fine, but when I try to pass any other image that is not from the dataset I get this error:


ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 32, 32, 1)

I do reshape the image, but can not figure out why I am getting that error and failing every pass


image = load_img("image.jpeg", grayscale="false", color_mode="rgb", target_size=(32, 32))
image = img_to_array(image)
image = image.reshape(3, 32, 32, 1)
image = image.astype('float32')
image = image / 255.0

How do I go about solving this issue and reshaping the image correctly?

Thanks in advance!

image = image.reshape(3, 32, 32, 1)

Should be:
image = image.reshape(3, 32, 32)

 

Hello, I made an image recognition model in python using keras, this is the input shape: 

input_shape=(3, 32, 32)

The model itself works fine, but when I try to pass any other image that is not from the dataset I get this error:

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 32, 32, 1)

I do reshape the image, but can not figure out why I am getting that error and failing every pass

image = load_img("image.jpeg", grayscale="false", color_mode="rgb", target_size=(32, 32))
image = img_to_array(image)
image = image.reshape(3, 32, 32, 1)
image = image.astype('float32')
image = image / 255.0

How do I go about solving this issue and reshaping the image correctly?

Thanks in advance!

Link to comment
Share on other sites

Link to post
Share on other sites

please post the image and the whole code as well as the entire output of the program so we can see the context of the error.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

On 1/7/2021 at 7:36 AM, Zuccers said:

 

Hello, I made an image recognition model in python using keras, this is the input shape: 


input_shape=(3, 32, 32)

The model itself works fine, but when I try to pass any other image that is not from the dataset I get this error:


ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 32, 32, 1)

I do reshape the image, but can not figure out why I am getting that error and failing every pass


image = load_img("image.jpeg", grayscale="false", color_mode="rgb", target_size=(32, 32))
image = img_to_array(image)
image = image.reshape(3, 32, 32, 1)
image = image.astype('float32')
image = image / 255.0

How do I go about solving this issue and reshaping the image correctly?

Thanks in advance!

image = image.reshape(3, 32, 32, 1)

Should be:
image = image.reshape(3, 32, 32)

FX6300 @ 4.2GHz | Gigabyte GA-78LMT-USB3 R2 | Hyper 212x | 3x 8GB + 1x 4GB @ 1600MHz | Gigabyte 2060 Super | Corsair CX650M | LG 43UK6520PSA
ASUS X550LN | i5 4210u | 12GB
Lenovo N23 Yoga

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×