1
$\begingroup$

I am a beginner to image classification and apologies beforehand if the question I am asking is dumb. I am currently using the following model:

baseModel = VGG16(weights="imagenet", include_top=False,
    input_tensor=Input(shape=(224, 224, 3)))

# construct the head of the model that will be placed on top of the base model
headModel = baseModel.output
headModel = Flatten(name="flatten")(headModel)
headModel = Dense(64, activation=tf.nn.leaky_relu)(headModel)
headModel = Dropout(0.5)(headModel)
headModel = Dense(2, activation="softmax")(headModel)
model = Model(inputs=baseModel.input, outputs=headModel)

For this model, I am doing a binary image classification. The model is compiled as such:

opt = Adam(lr=INIT_LR, decay=INIT_LR / EPOCHS)
model.compile(loss="binary_crossentropy", optimizer=opt,
    metrics=["accuracy"])

This model will give a 100% for both the training and validation accuracy. I wanted to understand how the model is activated for certain images. So I tried to calculating the heatmap. However in one of the calculations we have:

    def compute_heatmap(self, image, eps=1e-8):

        gradModel = Model(
            inputs=[self.model.inputs],
            outputs=[self.model.get_layer(self.layerName).output,
                     self.model.output])

        with tf.GradientTape() as tape:
            inputs = tf.cast(image, tf.float32)
            (convOutputs, predictions) = gradModel(inputs)
            loss = predictions[:, self.classIdx]

        grads = tape.gradient(loss, convOutputs)

The gradient is calculated from the loss which is roughly zero since the accuracy is 100%. This will result in a bank/flat heatmap.

When this happens, how should I deal with class activation mapping?

Sorry for the long post and any help will be appreciated!

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.