Question

I have done research but cannot seem to find what's wrong here

I have created this model for Mnist digit clasification :

import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D , MaxPool2D,Dropout,Flatten
from tensorflow.keras.datasets import mnist


model = Sequential()
model.add(Conv2D(filters = 32 , kernel_size = (3,3),activation ='relu' , input_shape = input_shape ))
model.add(Conv2D(64,(3,3),activation = 'relu'))
model.add(MaxPool2D(2,2))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128,activation = 'relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation ='softmax'))

and I have this image to feed into the model:

enter image description here

So i reshaped the image like this:

from skimage import data
from skimage.transform import resize
image = image_gray
image = resize(image, (28, 28,1)).shape
image

But when i try to predict using this image i get this error:

ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (3, 1)

I have tried multiple ways using skimage but I can't seem to get the model to fit. What can I do?

Was it helpful?

Solution

model.predict(img) requires a batch axis, i.e. img needs to have a shape of (BS, H, W, C). Try model.predict(np.expand_dims(img,0)).

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top