I am using keras to load in my model.h5(a file of weights) for my CNN. I am using a VGG-16 Architecture. My training data consists of numpy array of size (2590, 3(for RGB), 875(pixels in width), 375(pixels in height)). I have finished training the data and now I am using the model.h5(with weights) to make a prediction. I am running into the following error.
expected zero_padding2d_1_input to have shape (None, 3, 875, 375) but got array with shape (1, 375, 875, 3)
Here is the top snippet of my VGG-16 CNN
def VGG_16(weights_path=None):
model = Sequential()
model.add(ZeroPadding2D((1,1),input_shape=(3,875,375)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
.......... Continued ..........
Here is what I've tried First: I looked at these posts: Error when checking target: expected dense_20 to have shape (None, 3) but got array with shape (1200, 1)
Code I am trying:
model = VGG_16('/path/to/weights/file....../model.h5')
print("Created model")
img = np.array([np.array(Image.open(path_to_image_i_want_to_convert))])
img.reshape(1, 3, 875,375)
try:
prediction = model.predict(img)
print(prediction)
print("I finished your prediction")
except Exception as e:
print(str(e))
However, This always raises an error.
expected zero_padding2d_1_input to have shape (None, 3, 875, 375) but got array with shape (1, 375, 875, 3)
How can a numpy array even have a dimension of None? What am I doing wrong? How can I modify my code in order to make a prediction with only a single image.
Any help would be appreciated thanks!