sicara / tf-explain

Interpretability Methods for tf.keras models with Tensorflow 2.x
https://tf-explain.readthedocs.io
MIT License
1.02k stars 111 forks source link

[Bug Report] - Error in true_divide -> All ResnetV2 Keras Models #130

Open Meywether opened 4 years ago

Meywether commented 4 years ago

Dear Sicara, thanks for this great easy-to-use library. I do have to mention a bug in your script if I am using one of the ResnetV2 Models: Starting with a small modified version of your provided example, tf-explain throws following error by using:

The "V1" Versions are working properly. -> Tested with all three variants!

The script throws following error:

image

Thanks in advance! Best regards Meywether

Attached: My version of your provided example:

image

RaphaelMeudec commented 4 years ago

@Meywether This might be due to heatmap.min being equal to heatmap.max. You might want to remove the last softmax layer of the Resnet to prevent this from happening.

nishantagarwal commented 4 years ago

@Meywether This might be due to heatmap.min being equal to heatmap.max. You might want to remove the last softmax layer of the Resnet to prevent this from happening.

@RaphaelMeudec is right here. Even I had the same issue. I resolved it by removing the last layer from my pre-trained model.

Meywether commented 4 years ago

Hello @RaphaelMeudec and @nishantagarwal , thanks for your response.

model = tf.keras.applications.resnet_v2.ResNet50V2(weights="imagenet", include_top=False) - is not working

So I created a second model by using: model2 = Model(model.input, model.layers[-2].output)

model2.summary() shows me that the props layer is gone, but still getting the same error

I thought that model2 = Model(model.input, model.layers[-1].output) should be enough but in my case the Dense probs layer was still in my model.

May I ask you to provide me a code snippet ?

Best regards

Meywether

Ram-WD commented 3 years ago

I have the same problem as @Meywether , with a custom keras model with multi output ( segmentation and classification).