albermax / innvestigate

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

LRP visualization problem #218

Closed t-softic closed 3 years ago

t-softic commented 3 years ago

Dear,

I have implemented my CNN in tensorflow and since there are problems in compatibility, in order to use your software I had to create same network from scratch with pure keras and than load weights from my model. After that I used your code for LRP and it works fine, but it is reversed from what am I expecting. It shows that white background is affecting classification the most (in blue and red on LRP plot) and part of image that represents main object is not considered (white on LRP plot), and as far as I know it should be other way around. Also my classifier has around 93% accuracy, so I think the problem is not there. Can you tell me maybe what am I doing wrong? Code for visualization of analyzer is below. Thanks!

model=create_model() model.load_weights(load_model_path)

model = iutils.keras.graph.model_wo_softmax(model) analyzer = innvestigate.create_analyzer("lrp.z", model)

color_conversion = None
channels_first = keras.backend.image_data_format == "channels_first"

def postprocess(X): X = X.copy() X = iutils.postprocess_images(X, color_coding=color_conversion, channels_first=channels_first) return X

def heatmap(X): return ivis.heatmap(X)

"""Load an image.""" image = load_image( os.path.join(image_path), 224)

"""Show original image""" plt.imshow(image/255) plt.axis('off') plt.savefig("example_image.png")

"""Apply analyzer""" a = analyzer.analyze(image[None,:,:,:]) """Plot""" a=postprocess(a) a=heatmap(a) plt.imshow(a[0]) plt.axis('off') plt.savefig("example_analysis.png")

rachtibat commented 3 years ago

Hi,

have you looked at https://github.com/albermax/innvestigate/issues/215 ?

Otherwise, it might be possible that the model is looking at the environment to get the prediction. You could try out either

  1. other explanation libraries or
  2. cut the object out of your image and run the prediction again.

If you find in other libraries other results, I would be glad, if you share the knowledge with us! Best

rachtibat commented 3 years ago

due inactivity