deep-learning-models
deep-learning-models copied to clipboard
How to get pool_3 layer from inception using Keras
I used the following code following example in Readme.md
base_model = InceptionV3(include_top=False, weights='imagenet')
model = Model(input=base_model.input, output=base_model.get_layer('pool_3').output)
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)
pool_3_features = model.predict(x)
I get following error. What am I doing wrong.
Traceback (most recent call last):
File "inception_v3.py", line 420, in <module>
model = Model(input=base_model.input, output=base_model.get_layer('pool_3').output)
AttributeError: 'NoneType' object has no attribute 'output'
I got this code to work
model = InceptionV3(weights='imagenet', include_top=False)
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)
Is it getting pool_3 layer or some other layer. dimensions seems to match.
model.summary() will print all the layers (along with the dimensions and parameters).
@prashanthdumpuri Is there a way to look at specific layers from the summary? Inception has over 300 layers. Say I want to look at 35-50, is there a way to do this?
base_model = InceptionV3(weights='imagenet')
for i, layer in enumerate(base_model.layers): print(i, layer.name)
This will print the name of every layer. So you can use a shortened for loop if you want to see specific layers.
And am pretty sure there is a layer summary as well. Check out https://github.com/fchollet/keras/blob/master/keras/utils/layer_utils.py
Hope that helps. Prashanth
On Nov 26, 2017, at 12:57 PM, Moondra [email protected] wrote:
@prashanthdumpuri Is there a way to look at specific layers from the summary? Inception has over 300 layers. Say I want to look at 35-50, is there a way to do this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@prashanthdumpuri Thank you very much.