python-3.x - Keras 中特征提取的 ResNet50 输入问题
问题描述
我正在使用预训练的 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))
推荐阅读
- mysql - 检查用户名列中是否存在 UserA 和 UserB
- python - MySQL Aurora 数据库返回 True 值以响应具有空值的字段
- firebase - 如何将存储在一个变量中的数据添加到 Nuxt 中数据返回内的另一个数据字段?
- laravel - 使用 curl 获取帖子响应并将其发送给 laravel api
- api - Vue.js API 过滤唯一项以选择和删除空/空值
- javascript - 如何仅显示绘制形状的相交部分(javascript)?
- java - DFS(深度优先搜索)节点序列
- python - ModuleNotFoundError:没有名为“袖扣”的模块
- c# - 通过 VSTO 插件获取 EWS 身份令牌
- android - 如何为自定义绘制的小部件添加阴影?