GradCAM for MoViNet

38 Views Asked by At

I am trying to implement GradCAM using the MoViNet a2-stream backbone with a finetuned classifier on my custom dataset, but I am struggling to build the gradient model.

When building a MoViNet model, according to the summary() method, we get three layers: Images (input), Movinet (backbone), and the custom classifier. My questions are:

  • First, I am not sure where to find the last convolutional layer for computing gradients. Looking at the A2-architecture graph in the original paper, I guess I need to access the conv_7 layer, but not sure if it is included in the Movinet backbone or the Classifier.
  • If I assume this last convolutional layer is the head sublayer in the backbone (found with summary() method), I get the following error when running this chunk of code for building the gradient model:
    movinet_backbone = finetuned_model.get_layer('movinet')
    gradModel = Model(inputs=movinet_backbone.inputs,
                      outputs=[movinet_model.get_layer('head').output, finetuned_model.output])
    
    ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, None, None, None, 3), dtype=tf.float32, name='inputs'), name='inputs', description="created by layer 'inputs'") at layer "stem". The following previous layers were accessed without issue: []
    
    I am not sure that I am selecting the correct layer with this approach, as this head layer is part of the frozen backbone and, therefore, not trained. However, I am getting this error with any other layer in the backbone. At the same time, the classifier layer does not contain nested layers to access. I also do not know how to deal with all the state blocks provided when running movinet_model.get_layer('head').output.
  • Do you think GradCAM is actually feasible with this type of architecture?

I would appreciate any feedback provided. Thanks.

Notes: I have followed the training procedure explained in this tutorial without any issues. I can also load and evaluate the finetuned model.

0

There are 0 best solutions below