Replacing "ReLU" with "ReLU6" for Guided GradCAM visualization

Viewed 31

I am trying to implement Guided GradCAM to understand my custom MobileNetV2 model predictions.

In the following block of code, is it fine to replace 'Relu' with 'Relu6' (since authors of MobilenetV2 have used Relu6 as the activation)?

Asking this particularly because Guided GradCAM sort of gives a strange pattern when I used 'Relu', but the results are pretty good when I change it to 'Relu6'.

def build_guided_model():
    if "GuidedBackProp" not in ops._gradient_registry._registry: #avoid over-write
        @ops.RegisterGradient("GuidedBackProp")
        def _GuidedBackProp(op, grad):
            dtype = op.inputs[0].dtype
            return grad * tf1.cast(grad > 0., dtype) * \
                   tf1.cast(op.inputs[0] > 0., dtype)

    g = tf1.get_default_graph()       #guidedbackdrop in another copy
    with g.gradient_override_map({'Relu': 'GuidedBackProp'}):
        new_model = load_model('model.h5')
    return new_model
0 Answers
Related