Image_classification使用带有图像网络数据库的 resnet50 模型以及我的自定义标签



我正在研究image_classification问题(多类(。 我正在使用 Resnet50 模型(https://keras.io/applications/#classify-imagenet-classes-with-resnet50(以及使用 Keras 的预训练数据库"ImageNet">

我正在获取我传递给模型的图像的输出标签。

但是现在, 我有我自己的数据集的图像数据和标签数据。

当我将图像传递给 resnet50 模型时,它会返回已经训练的图像网标签。现在,在这里,我希望输出作为我自己的标签,该标签已经在数据集中,而不是获取 imagenet 标签。

如何在 resnet50 模型中使用 keras 中的 imagenet db 微调标签

我已经单独尝试了resnet50模型,它工作正常。 但是,如何将输出更改为我自己的标签而不是 ImageNet 预先训练的标签。


from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
import os
model = ResNet50(weights='imagenet')
path='/Users/resnet-sample/'
img_path=os.listdir(path)
count=0
for i in img_path:
img = image.load_img(path+i, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
print('Predicted:', decode_predictions(preds, top=1)[0], i)
count=count+1
print(preds)

例:

我有一个JPG格式的大象图像,并在我的数据集中将其标记为"大象"。

当我将此图像传递给使用ImageNet预训练数据库的Resnet50模型时,我收到的输出是"非洲大象"(Imagenet-label(。

因此,与其将 imagenet 标签作为输出,我想将其调整为我的数据集中的"大象"作为标签。

因此,不确定如何微调输出为我的标签而不是图像网标签的最后一层。

佩拉塞帮我解决这个问题。

谢谢

Srknt73

weights参数应为None(随机初始化(、imagenet(在 ImageNet 上进行预训练(或要加载的权重文件的路径。因此,您可以提供包含数据集标签的文件的路径

最新更新