Average Drop and Average Increase Metrics

class image_segmentation.class_activation_maps.average.AveragesCam(model: tensorflow.keras.Model, inputs: tensorflow.Tensor)[source]

Set of metrics to measure influence of CAM in the ouput model score.

model

Already trained model.

Type:

tensorflow.keras.Model

inputs

Instances to predict scores.

Type:

tf.Tensor

__init__(model: tensorflow.keras.Model, inputs: tensorflow.Tensor) None[source]
Parameters:
  • model – Already trained model.

  • inputs – Instances to predict scores.

_get_scores(cams: tensorflow.Tensor, score_function: Callable) tuple[source]

Calculate scores over inputs and masked inputs with cams.

Parameters:
  • cams – Normalized ouput of CAM methods using the model and the inputs

  • score_function – Same score function used to calculate the CAMs in tf-keras-vis

Returns:

The fisrt is the scores of the model over the inputs and the second is the scores over the masked input with the cams.

Return type:

tuple

average_drop(cams: tensorflow.Tensor, score_function: Callable, return_vector: bool = False) float[source]

Calculate average drop.

Parameters:
  • cams – Normalized ouput of CAM methods using the model and the inputs

  • score_function – Same score function used to calculate the CAMs in tf-keras-vis

Returns:

average drop

Return type:

float

Note

The equation used is

\[100\frac{1}{N} \sum_{i=1}^N \frac{max(0,Y_i^c - O_i^c)}{Y_i^c}\]
average_increase(cams: tensorflow.Tensor, score_function: Callable, return_vector: bool = False) float[source]

Calculate average increase.

Parameters:
  • cams – Normalized ouput of CAM methods using the model and the inputs

  • score_function – Same score function used to calculate the CAMs in tf-keras-vis

Returns:

average increase

Return type:

float

Note

The equation used is

\[100\frac{1}{N} \sum_{i=1}^N Sign(Y_i^c < O_i^c)\]
image_segmentation.class_activation_maps.average.avg_drop(Y_c, O_c)[source]
image_segmentation.class_activation_maps.average.avg_increase(Y_c, O_c)[source]