albermax / albermax/innvestigate

[BUG] Getting negative LRP relevance value for Alpha_1_beta_0 rule when analyzing the ResNet model

オープン
#326 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
triage
主要言語
Python
スター
1.3k
フォーク
230
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi,
I am facing problem in visualizing the heatmaps when I train ResNet model and use the LRP for visualizing the heatmaps of the cats and dog image dataset. Below I have attached the heatmap of the lrp relevance (analyzer output) on left side , masked lrp on top of original image (right side image) and also attached is the distribution plot of the relevance matrix (analyzer output relevance values). I found out that for many images I am getting negative relevances even if I use alpha_1_beta_0 (consider only positive relevances) rule. I do not face this issue when I use simple CNN mode, VGG16 model. What could be the reason of the negative relevance in ResNet for alpha_1_1bata_0 rule? How to fix it. Kindly help me to fix it.

Thanks in advance

```
#Resnet Tiny Model
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Input, Conv2D, BatchNormalization, ReLU, Add, AveragePooling2D, Flatten, Dense
from tensorflow.keras.models import Model
from tensorflow.keras.utils import plot_model

def residual_block(x, filters, stride=1):
shortcut = x

x = Conv2D(filters, kernel_size=(1, 1), strides=stride, padding='same', data_format='channels_last')(x)
x = BatchNormalization()(x)
x = ReLU()(x)

x = Conv2D(filters, kernel_size=(3, 3), padding='same')(x)
x = BatchNormalization()(x)

if stride != 1:
shortcut = Conv2D(filters, kernel_size=(1, 1), strides=stride)(shortcut)
shortcut = BatchNormalization()(shortcut)

x = Add()([x, shortcut])
x = ReLU()(x)
return x

def tiny_resnet(input_shape, num_classes, **modelParams):
print('input_shape: ', input_shape, input_shape[1:]) #input_shape: (1800, 124, 124, 3)
inputs = Input(shape=input_shape[1:])

x = Conv2D(64, kernel_size=(5, 5), strides=2, padding='same')(inputs)
x = BatchNormalization()(x)
x = ReLU()(x)
x = AveragePooling2D(pool_size=(3, 3), strides=2, padding='same', data_format='channels_last')(x)

# Only one residual block
x = residual_block(x, 64)

x = AveragePooling2D(pool_size=(3, 3))(x)

x = Flatten()(x)
x = Dense(num_classes, activation='softmax')(x)

model = Model(inputs=inputs, outputs=x)
plot_model(model, to_file='tiny_resnet_diagram.png', show_shapes=True, show_layer_names=True)
return model
```

### Expected behavior
I should get only the positive relevance values as I am using the lrp.alpha_1_beta_0 rule.

### Screenshots
If applicable, add screenshots to help explain your problem.
![12136_cat](https://github.com/albermax/innvestigate/assets/23495348/7f18593f-8e8e-45f6-a681-6869ef1cbb3c)
![12136_cat_dist_preNorm](https://github.com/albermax/innvestigate/assets/23495348/043203ac-8f74-4a07-b78f-f1c2966ef265)

Original test Image:
![12136](https://github.com/albermax/innvestigate/assets/23495348/7cd6919b-7d67-467e-a8a5-0ab913a4f3b7)

### Platform information
- OS: [Windows 11]
- Python version: [3.8]
- iNNvestigate version: [version 1, and also with v2.1.2]
- TensorFlow version: [2.5]

### Model Trained on Cat and Dog Dataset
[model.zip](https://github.com/albermax/innvestigate/files/14075479/model.zip)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。