Jür*_* K. 6 python classification deep-learning keras vgg-net
我使用Keras预训练的VGG-16型号.
到目前为止我的工作源代码是这样的:
from keras.applications.vgg16 import VGG16
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.applications.vgg16 import decode_predictions
model = VGG16()
print(model.summary())
image = load_img('./pictures/door.jpg', target_size=(224, 224))
image = img_to_array(image) #output Numpy-array
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
image = preprocess_input(image)
yhat = model.predict(image)
label = decode_predictions(yhat)
label = label[0][0]
print('%s (%.2f%%)' % (label[1], label[2]*100))
Run Code Online (Sandbox Code Playgroud)
我宣布该模型已经训练了1000个班级.有没有可能得到这个模型训练的类列表?打印出所有预测标签不是一种选择,因为只返回了5个.
提前致谢
您可以使用 decode_predictions 并在top=1000参数中传递类的总数(只有其默认值为 5)。
或者您可以查看 Keras 如何在内部执行此操作:它下载文件imagenet_class_index.json(通常将其缓存在 中~/.keras/models/)。这是一个包含所有类标签的简单 json 文件。
| 归档时间: |
|
| 查看次数: |
6065 次 |
| 最近记录: |