Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.applications.vgg16 import VGG16, preprocess_input
- from keras.preprocessing.image import load_img,img_to_array
- from keras.models import Model
- import matplotlib.pyplot as plt
- import numpy as np
- model = VGG16()
- layer_dict = dict([(layer.name, layer) for layer in model.layers])
- layer_name = 'block1_conv2'
- model = Model(inputs=model.inputs, outputs=layer_dict[layer_name].output)
- # Perpare the image
- image = load_img('tiger.jpg', target_size=(224, 224))
- image = img_to_array(image)
- image = np.expand_dims(image, axis=0)
- image = preprocess_input(image)
- # Apply the model to the image
- feature_maps = model.predict(image)
- square = 8
- index = 1
- for _ in range(square):
- for _ in range(square):
- ax = plt.subplot(square, square, index)
- ax.set_xticks([])
- ax.set_yticks([])
- plt.imshow(feature_maps[0, :, :, index-1], cmap='viridis')
- index += 1
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement