【问题标题】:ResNet50 input issue for feature extraction in KerasKeras 中特征提取的 ResNet50 输入问题
【发布时间】:2019-10-21 13:43:26
【问题描述】:

我正在使用预训练的 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()

【问题讨论】:

    标签: python-3.x keras computer-vision resnet


    【解决方案1】:

    改变

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

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

    【讨论】:

    • 我看到了一个小姐类型。谢谢你,我已经坚持了大约一个小时了。
    • 这花了我 5 分钟才看到。 target_size 参数中的区别是 244224
    猜你喜欢
    • 2017-09-06
    • 2016-12-05
    • 2019-10-28
    • 2021-04-11
    • 1970-01-01
    • 2023-01-21
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多