oarriaga/face_classification

K.gradients got None in grad_cam.py line 115

Opened this issue · 2 comments

K.gradients got None in grad_cam.py line 115, this cause the normalize function at line 29, throw an exception:

gradients = K.gradients(loss, conv_output)

the same error @equiclouds

first add this function in this file:

def _compute_gradients(tensor, var_list):
    grads = tf.gradients(tensor, var_list)
    return [grad if grad is not None else tf.zeros_like(var)
        for var, grad in zip(var_list, grads)]

then change the lines above "return" in "compile_gradient_function function" to below:

    gradients = normalize(_compute_gradients(loss, [conv_output])[0])
    gradient_function = K.function([model.layers[0].get_input_at(0), K.learning_phase()],
                                   [conv_output, gradients])