Skip to content

keras-style API to ResNets (ResNet-50, ResNet-101, and ResNet-152)

Notifications You must be signed in to change notification settings

statechular11/resnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ResNet

Overview

ResNet serves as an extension to Keras Applications to include

  • ResNet-101
  • ResNet-152

The module is based on Felix Yu's implementation of ResNet-101 and ResNet-152, and his trained weights. Slight modifications have been made to make ResNet-101 and ResNet-152 have consistent API as those pre-trained models in Keras Applications. Code is also updated to Keras 2.0.

Installation

pip install resnet

Usuage

import resnet
import numpy as np
from keras.preprocessing.image import load_img, img_to_array

#-------------------------------------
#   Load pre-trained models
#-------------------------------------
resnet50  = resnet.ResNet50(weights='imagenet')
resnet101 = resnet.ResNet101(weights='imagenet')
resnet152 = resnet.ResNet152(weights='imagenet')

#-------------------------------------
#   Helper functions
#-------------------------------------
def path_to_tensor(image_path, target_size):
    image = load_img(image_path, target_size=target_size)
    tensor = img_to_array(image)
    tensor = np.expand_dims(tensor, axis=0)
    return tensor

#-------------------------------------
#   Make predictions
#-------------------------------------
image_path = 'examples/images/dog.jpeg'
image_tensor = path_to_tensor(image_path, (224, 224))
pred_resnet50  = np.argmax(resnet50.predict(image_tensor))
pred_resnet101 = np.argmax(resnet101.predict(image_tensor))
pred_resnet152 = np.argmax(resnet152.predict(image_tensor))

Sample dog image

The above dog image is predicted to have

  • 257: 'Great Pyrenees' by ResNet-50
  • 257: 'Great Pyrenees' by ResNet-101
  • 257: 'Great Pyrenees' by ResNet-152

Contact

If you have any questions or encounter any bugs, please contact the author (Feiyang Niu, statech.forums@gmail.com)

References

  • He and etc 2015 Deep Residual Learning for Image Recognition arXiv:1512.03385
  • Felix Yu's original implementation of ResNet-101 is found here and ResNet-152 here.

About

keras-style API to ResNets (ResNet-50, ResNet-101, and ResNet-152)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages