qubvel / resnet_152

Pretrained on ImageNet ResNet-152 model in Keras

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ResNet-152 model for Keras

Reference:

Extention of model taken here.
Model made in Keras style with pretrained weights from ImageNet provided in release (load automatically during model initialization).

Example

Inference example for this picture:

Code
import numpy as np
from skimage.io import imread
from skimage.transform import resize
from keras.applications.imagenet_utils import decode_predictions
from keras.applications.imagenet_utils import preprocess_input
from model import ResNet152

# create model
model = ResNet152()

# define function for input preprocessing
def preprocess(x):
    x = resize(x, (224,224), mode='constant') * 255
    x = preprocess_input(x)
    if x.ndim == 3:
        x = np.expand_dims(x, 0)
    return x

# prepare image
img = imread('./imgs/cat.jpg')
x = preprocess(img)

# make prediction and decode it
y = model.predict(x)
pred_title = decode_predictions(y, top=1)[0][0][1]

# print result
print(pred_title)
### tiget_cat

About

Pretrained on ImageNet ResNet-152 model in Keras


Languages

Language:Python 100.0%