Reputation: 2743
I am using a pre-trained Resnet50 model for simple feature extraction for images. but it gives me this error.
Error when checking input: expected input_9 to have the shape (224, 224, 3) but got array with shape (244, 244, 3)
I thought I changed the shape correctly and added a dimension to it like this tutorial said to do. https://www.kaggle.com/kelexu/extract-resnet-feature-using-keras
But it still gives me the above error.
What am I doing wrong here?
# load pre-trained resnet50
base_model = ResNet50(weights='imagenet', include_top=False,pooling=max)
x = base_model.output
input = Input(shape=(224,224,3))
x = Flatten()(input)
model = Model(inputs=input, outputs=x)
# Load in image
img = image.load_img("001.png", target_size=(244, 244))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
print(x.shape) # This produces (1, 244, 244, 3)
features = model.predict(x)
features_reduce = features.squeeze()
Upvotes: 0
Views: 1680
Reputation: 2917
Change
img = image.load_img("001.png", target_size=(244, 244))
to
img = image.load_img("001.png", target_size=(224, 224))
Upvotes: 2