-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathresnet50_example.py
30 lines (25 loc) · 1009 Bytes
/
resnet50_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
'''ResNet50 model for Keras.
# Reference:
- [Deep Residual Learning for Image Recognition](https://arxiv.org/abs/1512.03385)
Adapted from code contributed by BigMoyan.
'''
from __future__ import print_function
import numpy as np
import warnings
from keras.layers import Input
from keras import layers
from keras.preprocessing import image
from keras.applications.imagenet_utils import decode_predictions
from keras.applications.imagenet_utils import preprocess_input
from keras.applications.resnet50 import ResNet50
if __name__ == '__main__':
model = ResNet50(include_top=True, weights='imagenet')
img_path = 'data\\dogscats\\train\\cats\\cat.10013.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)
print('Input image shape:', x.shape)
preds = model.predict(x)
print('Predicted:', decode_predictions(preds)) # ('n02123394', 'Persian_cat', 0.87062669)