Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported model architecture for VanillaGradients #182

Open
khaledbouabdallah opened this issue Mar 28, 2022 · 1 comment
Open

Unsupported model architecture for VanillaGradients #182

khaledbouabdallah opened this issue Mar 28, 2022 · 1 comment

Comments

@khaledbouabdallah
Copy link

I'm trying to use VanillaGradients for a single image, but I'm getting this warning

UserWarning: Unsupported model architecture for VanillaGradients. The last two layers of the model should be: a layer which computes class scores with no activation, followed by an activation layer.

VanillaGradients call :

img = tf.keras.preprocessing.image.load_img(image_path,target_size=IMG_SHAPE)
img = tf.keras.preprocessing.image.img_to_array(img)
img = np.array(img) / 255

data = ([img], None)

explainer = VanillaGradients()
grid = explainer.explain(data,model,0)

Model Declaration

model = Sequential()
model.add(Conv2D(32 , (3,3) , strides = 1 , padding = 'same' , activation = 'relu' , input_shape = (150,150,3)))
model.add(BatchNormalization())
model.add(MaxPool2D((2,2) , strides = 2 , padding = 'same'))
model.add(Conv2D(64 , (3,3) , strides = 1 , padding = 'same' , activation = 'relu'))
model.add(Dropout(0.1))
model.add(BatchNormalization())
model.add(MaxPool2D((2,2) , strides = 2 , padding = 'same'))
model.add(Conv2D(64 , (3,3) , strides = 1 , padding = 'same' , activation = 'relu'))
model.add(BatchNormalization())
model.add(MaxPool2D((2,2) , strides = 2 , padding = 'same'))
model.add(Conv2D(128 , (3,3) , strides = 1 , padding = 'same' , activation = 'relu'))
model.add(Dropout(0.2))
model.add(BatchNormalization())
model.add(MaxPool2D((2,2) , strides = 2 , padding = 'same'))
model.add(Conv2D(256 , (3,3) , strides = 1 , padding = 'same' , activation = 'relu'))
model.add(Dropout(0.2))
model.add(BatchNormalization())
model.add(MaxPool2D((2,2) , strides = 2 , padding = 'same'))
model.add(Flatten())
model.add(Dense(units = 128 , activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(units = 1 , activation = 'sigmoid'))

Notes

  • GRAND CAM and occlusion are working as expected but all gradient-based methods results in the same warning
  • I'm working on binary classification
@E0HYL
Copy link

E0HYL commented May 2, 2022

I met the same problem when running with a model where the last layer is Dense with an activation function.
I checked the paper of Vinilla Gradients. In Section 2, the authors pointed that

It should be noted that we used the (unnormalised) class scores S_c, rather than the class posteriors, returned by the soft-max layer... The reason is that the maximisation of the class posterior can be achieved by minimising the scores of other classes.

Guess this is the reason why the warning is raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants