这篇教程利用ResNet50网络进行ImageNet分类写得很实用,希望能帮到您。
利用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
-
model = ResNet50(weights='imagenet')
#仅仅这样就可以
img_path = 'elephant.jpg'
img = image.load_img(img_path, 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)
# decode the results into a list of tuples (class, description, probability)
# (one such list for each sample in the batch)
print('Predicted:', decode_predictions(preds, top=3)[0])
# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458
keras画图cnn keras笔记(3)-猫狗数据集上的训练以及单张图片多张图片的测试 |