به نام خدا

استفاده از شبکه‌های از قبل آموزش داده شده

خطای رایج:
[cannot download vgg16_weights](https://github.com/fchollet/deep-learning-models/issues/33)
راهکار؟

You can download it manually from here: https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5 and paste it on ~/.keras/models

In [1]:
import os
os.path.expanduser('~/.keras/models')
Out[1]:
'C:\\Users\\alire/.keras/models'
In [2]:
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input, decode_predictions
import numpy as np
Using TensorFlow backend.
In [3]:
model = VGG16(weights='imagenet')
In [4]:
img_path = './image/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: [('n02504458', 'African_elephant', 0.75150585), ('n01871265', 'tusker', 0.20827964), ('n02504013', 'Indian_elephant', 0.04021414)]
دوره مقدماتی یادگیری عمیق
علیرضا اخوان پور
پنج شنبه، ۲۵ بهمن ۱۳۹۷
Class.Vision - AkhavanPour.ir - GitHub