Open wosiu opened 6 years ago
I created an example with VGG 16. Please refer to below. It is executable.
from keras.applications import VGG16
from keras.models import Model
from keras.layers import Input
from keras import activations
from vis.utils import utils
from vis.losses import ActivationMaximization
from vis.regularizers import TotalVariation, LPNorm
from vis.visualization.activation_maximization import visualize_activation_with_losses
# Load VGG16 model
model = VGG16()
# Replace the activation of top layer
output_layer = model.layers[-1]
output_layer.activation = activations.linear
model = utils.apply_modifications(model)
# top layer
output_layer = model.layers[-1]
# Target intermediate layer
intermediate_layer = model.get_layer('block3_conv1')
losses = [
(ActivationMaximization(output_layer, 20), 1),
(LPNorm(intermediate_layer.input), 10),
(TotalVariation(intermediate_layer.input), 10)
]
result = visualize_activation_with_losses(intermediate_layer.input, losses
Keras, Tensorflow, keras-vis from pip I'm trying to visualize_activation_with_losses, however not from original model input.
And getting:
Original input of the model is indeed with shape [?,960,672,1]. However I would like to get intermediate images for each activation before convolution. Head of my architecture looks like this:
and as you noticed in code above, I want to get 16 activations of size 480x336 (like an image with 16 channels) which get into 6th layer (Conv).