In [3]:
%%bash
rm -rf deep-learning-models
git clone --depth=1 https://github.com/fchollet/deep-learning-models.git
In [4]:
%%bash
ls deep-learning-models
In [6]:
import sys
sys.path.insert(0, 'deep-learning-models')
In [7]:
from resnet50 import ResNet50
In [3]:
%%bash
pip2 list|grep keras
pip2 install -U keras
In [5]:
import sys
sys.path.insert(0, 'deep-learning-models')
In [32]:
import IPython.display as display
In [6]:
from resnet50 import ResNet50
In [9]:
import numpy as np
from keras.preprocessing import image
from imagenet_utils import preprocess_input, decode_predictions
model = ResNet50(weights='imagenet')
img_path = 'out.png'
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))
In [39]:
img_path = 'images/SNC12011.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)
decoded_preds = decode_predictions(preds)
for pred in decoded_preds:
for p in pred:
print '%30s\t%05.2f%%' % (p[1], p[2] * 100.0)
In [38]:
#IMG_1825.JPG
img_path = 'images/IMG_1825.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)
decoded_preds = decode_predictions(preds)
for pred in decoded_preds:
for p in pred:
print '%30s\t%05.2f%%' % (p[1], p[2] * 100.0)
In [41]:
from vgg16 import VGG16
from keras.preprocessing import image
from imagenet_utils import preprocess_input
model = VGG16(weights='imagenet', include_top=False)
img_path = 'images/SNC12011.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)
In [44]:
features.shape
Out[44]:
In [ ]:
from vgg19 import VGG19
from keras.preprocessing import image
from imagenet_utils import preprocess_input
from keras.models import Model
base_model = VGG19(weights='imagenet')
model = Model(input=base_model.input, output=base_model.get_layer('block4_pool').output)
img_path = 'images/SNC12011.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)
block4_pool_features = model.predict(x)
In [ ]: