#!/usr/bin/env python
# coding: utf-8
# In[1]:
from keras.applications.resnet50 import ResNet50
from quiver_engine import server
from keras.models import Model
# # Visualizing CNN's intermediate layer output
#
# We'll use [quiver](https://github.com/keplr-io/quiver) which works for Keras models.
# ![panda](../../assets/panda.png)
#
outputs of Resnet50's max_pooling2d_1 layer
# ## Model setup
#
# We use InceptionV3 but any model from `keras.application` could be used.
# In[2]:
input_shape = (224, 224, 3) # size of our image: width x height x number of channels
model = ResNet50(
include_top=False,
weights='imagenet',
input_shape=input_shape # quiver is going to need that
)
# Select intermediate layer (so that the graph is not too big)
# In[3]:
len(model.layers_by_depth)
# In[4]:
intermediate_layer = model.get_layer(name="add_3")
truncated_model = Model(inputs=[model.input], outputs=[intermediate_layer.output])
# In[5]:
print("Number of layers in truncated model:", len(truncated_model.layers))
truncated_model.summary()
# Sanity check - this should be `(None, 224, 224, 3)` (`None` corresponds to batch size)
# In[ ]:
truncated_model.get_input_shape_at(0)
# Be sure you ran
#
# ```
# make load_101_categories
# ```
#
# before you run that to setup the images.
#
# Also you could point *quiver* to other directory with images.
#
# Let's run the visualization engine!
# In[ ]:
imgs_path = "../../data/101_ObjectCategories/panda"
server.launch(
truncated_model,
temp_folder="../../data/tmp",
input_folder=imgs_path,
port=5000
)