You can use this to view the Keras Resnet Inception V2 network.
from keras.applications.inception_resnet_v2 import InceptionResNetV2, preprocess_input
from keras.layers import Input
model = InceptionResNetV2(weights='imagenet', include_top=True)
print(model.summary())
This will Output (im showing only the last few layers):
__________________________________________________________________________________________________
conv_7b_ac (Activation) (None, 8, 8, 1536) 0 conv_7b_bn[0][0]
__________________________________________________________________________________________________
avg_pool (GlobalAveragePooling2 (None, 1536) 0 conv_7b_ac[0][0]
__________________________________________________________________________________________________
predictions (Dense) (None, 1000) 1537000 avg_pool[0][0]
==================================================================================================
Total params: 55,873,736
Trainable params: 55,813,192
Non-trainable params: 60,544
__________________________________________________________________________________________________
None
If we look at the output of the 'avg_pool' layer from 'Top'. There will be 1536 features at the output.
You can make a model in this way:
from keras.applications.inception_resnet_v2 import InceptionResNetV2, preprocess_input
from keras.layers import Input
import numpy as np
def extract(image_path):
base_model = InceptionResNetV2(weights='imagenet', include_top=True)
model = Model(inputs=base_model.input,outputs=base_model.get_layer('avg_pool').output)
img = image.load_img(image_path, target_size=(299, 299))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
# Get the prediction.
features = model.predict(x)
features = features[0]
return features
features=[]
features = extract(image)
I couldn't try the code as, right now, I don't have an environment to test this code.