繁体   English   中英

用于Keras中特征提取的ResNet50输入问题

[英]ResNet50 input issue for feature extraction in Keras

我正在使用经过预先训练的Resnet50模型来进行图像的简单特征提取。 但这给了我这个错误。

Error when checking input: expected input_9 to have the shape (224, 224, 3) but got array with shape (244, 244, 3)

我以为我正确地改变了形状并像本教程所说的那样为其添加了尺寸。 https://www.kaggle.com/kelexu/extract-resnet-feature-using-keras

但这仍然给我上述错误。

我在这里做错了什么?

# 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()

更改

img = image.load_img("001.png", target_size=(244, 244))

img = image.load_img("001.png", target_size=(224, 224))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM