Metrics#
Build an evaluation metric. |
|
Final evaluation result that can be serialized to a JSON or yaml file. |
|
Re-inference based metric. |
|
Re-training based metric. |
|
Protocol of attribution (also known as explanation) methods. |
Building Functions#
build_metric#
General Protocols and Base Classes#
Serializable Result#
- protocol saliency_metrics.metrics.SerializableResult[source]#
Final evaluation result that can be serialized to a JSON or yaml file.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
Re-inference Based Metric#
- protocol saliency_metrics.metrics.ReInferenceMetric[source]#
Re-inference based metric.
A Metric implementing this protocol performs per-sample evaluation at inference time. Specifically, it first perturbs the input image according to the saliency map and then measure the degradation of the model’s prediction.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
- abstract evaluate(img, smap, target, **kwargs)[source]#
Perform evaluation on a single sample.
- Parameters
- Return type
- Returns
Evaluation result on a single sample.
Re-training Based Metric#
- protocol saliency_metrics.metrics.ReTrainingMetric[source]#
Re-training based metric.
A metric implementing this protocol re-trains a model on a perturbed dataset and evaluate the performance degradation.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
Attribution Method#
- protocol saliency_metrics.metrics.AttributionMethod[source]#
Protocol of attribution (also known as explanation) methods.
This protocol is mainly used in the Sanity Check metric, where an attribution method must implement this protocol.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
- abstract attribute(img, target, as_ndarray=True, interpolate=True, interpolate_args=None, **kwargs)[source]#
Attribute and produce the saliency map.
Note
The method performs attribution on single image, i.e., the local explanation.
- Parameters
img (
Tensor) – Input image with shape(1, num_channels, height, width).target (
Union[int,Sequence[int],Tensor]) – Ground-truth target.as_ndarray (
bool) – If True, then convert the saliency map into a ndarray.interpolate (
bool) – if True, then resize and interpolate the saliency map to the image’s spatial size.interpolate_args (
Optional[Dict]) – Other arguments for interpolation. See alsosaliency_metrics.utils.resize_img().**kwargs – Other keyword arguments for attribution.
- Return type
- Returns
A saliency map or a tuple of saliency maps.