Thanks to visit codestin.com
Credit goes to github.com

Skip to content

linzi-h/resnet152

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ResNet-152 for Keras

Adaptation of ResNet-152 to match Keras API with added large input option. Original code from flyyufelix, Keras 2.0 modified version of original code from mvoelk.

Weights are ported from Caffe by flyyufelix. Check out his blog for more info. Weights for feature extraction are adapted version of these weights with the top layer not included.

Weights can be found in the release section of this repo but the code is setup to download and cache the weights when the model is instantiated so there is no need to download them directly.

The weights are in TensorFlow format but the code is compatible with both TensorFlow and Theano backends and will convert weights into Theano format if needed.

Examples

This version is modified to work the same as the ResNet50 model currently available in keras.applications

Examples as provided by fchollet are compatible as shown below:

Classify images

from resnet152 import ResNet152
from keras.preprocessing import image
from keras.applications.imagenet_utils import preprocess_input, decode_predictions

model = ResNet152(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)
print(‘Predicted:’, decode_predictions(preds))
#Predicted: [[('n02504458', 'African_elephant', 0.57481891)]

Extract pool5 features from images

from resnet152 import ResNet152
from keras.preprocessing import image
from keras.applications.imagenet_utils import preprocess_input

model = ResNet152(include_top=False, 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)
    
features = model.predict(x)

Extract 14x14x2048 features from res5c

from resnet152 import ResNet152
from keras.preprocessing import image
from keras.applications.imagenet_utils import preprocess_input
from keras.models import Model

base_model = ResNet152(weights='imagenet', large_input=True)
model = Model(inputs=base_model.input, outputs=base_model.get_layer('res5c').output)
    
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(448,448))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
    
res5c_features = model.predict(x)

References

About

Adaptation of ResNet-152 to match Keras API with added large input option

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%