albermax / albermax/innvestigate

"This is not supposed to happen!" Exception with VGG16 and LRP

未關閉
#97 2 則留言 0 個 reaction 已指派 1 人 已被 @albermax 認領 在 GitHub 檢視
主要語言
Python
星號
1.3k
分支
230
PR 合併指標
30 天內沒有已合併 PR

描述

I was trying to use innvestigate (1.0.2) in combination with a finetuned vgg16 model which I created in keras.
When trying to analyze a given image, I am running into an Exception that only states that it is not supposed to happen.
Maybe I am using the analyzer in a wrong way or it can not deal with this model (did not have time to dig deeply into the LRP theory, but only saw that sigmoid activations can not be used..but they aren't used in VGG16 afaik)

Here is my code:
```python
from keras.applications import VGG16
from keras import Model
from keras.layers import Input, Flatten, Dense
import innvestigate

vgg = VGG16(weights='imagenet', include_top=False, input_shape=(128, 128, 3))
lname = "block5_conv2"
last_vgg_layer = vgg.get_layer(lname)
vgg_partial = Model(inputs=vgg.input, outputs=last_vgg_layer.output, name="Partial_VGG16_" + lname)
vgg_partial.trainable = False

inputs = Input(shape=(128, 128, 3))
x = vgg_partial(inputs)
x = Flatten()(x)
x = Dense(16, activation='relu')(x)
x = Dense(1, activation=None)(x)

model = Model(inputs=inputs, outputs=x)
print(model.summary())

def analyze_img(img, model):
analyzer = innvestigate.create_analyzer("lrp.z", model)

a = analyzer.analyze(img)
# somehow this seems necesarry since importing once and calling the
# function in a loop crashes after the first iteration (v.1.0.0)
from innvestigate.utils.visualizations import heatmap
return heatmap(a[0, :, :, :])

# Analyze.
img = np.ones((128, 128, 3))
print("img.shape", img.shape)

heat_train = analyze_img(img, model)
print(heat_train.shape)
```

which gives the following stacktrace:
![innvestigate_error](https://user-images.githubusercontent.com/31093529/44915791-368e4c00-ad34-11e8-8924-9806187f46e2.PNG)

I have installed the following packages:
```bash
Keras 2.2.0
Keras-Applications 1.0.2
tensorflow 1.10.0
innvestigate 1.0.2
````

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。