albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.25k stars 233 forks source link

iNNvestigate 2.0 LRP analyses returns empty list #208

Closed mariokloster closed 2 years ago

mariokloster commented 4 years ago

I tested it with LRPZ and return was a empty list. I'm not sure if I'm using the package correctly Can you pls help me

import tensorflow as tf
import matplotlib.pyplot as plt

from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt

import innvestigate

(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()

train_images, test_images = train_images / 255.0, test_images / 255.0

class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
               'dog', 'frog', 'horse', 'ship', 'truck']

model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))

model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

history = model.fit(train_images, train_labels, epochs=1,
                    validation_data=(test_images, test_labels))

analyser = innvestigate.create_analyzer("lrp.epsilon", model)

analysis = analyser.analyze(test_images[0])
albermax commented 4 years ago

did you try to call the library like this:

analysis = analyser.analyze(test_images[0:1])

?

mariokloster commented 4 years ago

Yes still it returns a empty list

mariokloster commented 4 years ago

Is there a version that works with tensorflow 2.x.x ?

rachtibat commented 4 years ago

We are still working on a 2.x.x version. Which branch of the project did you clone? The newest updates are in updates_towards_tf 2.0. But this branch might be unstable.

leanderweber commented 4 years ago

Hi, I found the bug, however, I will need some time to fix it.

In the meantime, it should work if you explicitly define an input layer, instead of using input_shape=... in the first convolutional layer.

mariokloster commented 4 years ago

Ty very much for your help

mariokloster commented 4 years ago

updates_towards_tf 2.0. works fine for me

adrhill commented 2 years ago

Closing this since iNNvestigate 2.0 is now released.