def compute_saliency_per_grad(grad_type, grad, data, target_layer, target_class=None):
    """
    Given the grad_type, computes saliency maps for a batch of images: data.
    :param grad_type:
    :param grad:
    :param data:
    :param target_layer: vgg: features, resnet: layer4
    :param target_class: To visualize wrong predictions take original target
    :return:
    """
    saliency = None

    if grad_type == "fullgrad" or grad_type == "inputgrad":
        # print("calculating saliency")
        saliency = grad.saliency(data, target_class=target_class)

    elif grad_type == "gradcam":
        probs, ids = grad.forward(data)
        # Grad-CAM
        grad.backward(ids=ids[:, [0]])
        saliency = grad.generate(target_layer=target_layer)

    return saliency