raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.97k stars 664 forks source link

Visualising MNIST Filters #109

Open CMCDragonkai opened 6 years ago

CMCDragonkai commented 6 years ago

Hi I'm trying this visualisation library and ran on a simple MNIST network.

I'm comparing activation maximisation used here from the the one described here: https://blog.keras.io/how-convolutional-neural-networks-see-the-world.html

The resulting filter visualisations are very different, but I expected that they should be similar in principle.

Here is what I get from using keras-vis:

gray_conv2_max_activations

Here's what I see when I use the one from the keras article:

gray_conv2_max_activations2

I'm wondering why the images look so different? When I look at the source code, your library is far more complex than the example in the keras blog. But it seems to work in a similar way, using a random seed image, and then gradient ascent.

model = models.Sequential(name='MNIST Keras')
model.add(
    Conv2D(
        32,
        kernel_size=(5, 5),
        activation='relu',
        input_shape=image_shape,
        padding='same',
        name='conv1'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same', name='pool1'))
model.add(
    Conv2D(
        64,
        kernel_size=(5, 5),
        activation='relu',
        input_shape=image_shape,
        padding='same',
        name='conv2'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same', name='pool2'))
model.add(Flatten())
model.add(Dense(1024, activation='relu', name='fc1'))
model.add(Dense(10, activation='relu', name='fc2'))
model.add(Dense(num_classes, activation='softmax', name='predictions'))
model.compile(
    loss=losses.categorical_crossentropy,
    optimizer=optimizers.Adam(),
    metrics=['accuracy'])

The model is very simple, and I'm only visualising the filters at conv2. The network was trained to:

loss: 0.0062 - acc: 0.9981 - val_loss: 0.0355 - val_acc: 0.9915
loss and accuracy: [0.03553478841514684, 0.9915]
CMCDragonkai commented 5 years ago

I decided not use this system for visualisation as it wasn't really understandable.

Instead I presented CNN visualisation paper a few weeks back in Sydney: https://www.meetup.com/Sydney-Paper-Club/events/pssrqpyxmbjb/

Deconvnets would need to be adapted to the resnet architecture as it was designed against the VGG16 architecture.