General API Reference

This page contains the API reference for the attribench package.

Computations and Metrics

Computations and metrics are divided into two API groups: a functional API and an object-oriented API. The functional API is the simplest to use, but does not support multi-GPU computations. If you want to run a large-scale benchmarking experiment on multiple GPUs, you should use the object-oriented API.

Results

attribench.result.MetricResult(method_names, ...)

Abstract class to represent results of distributed metrics.

attribench.result.GroupedMetricResult(...)

Abstract class to represent grouped results of distributed metrics.

attribench.result.DeletionResult(...)

Represents results from running the Deletion metric.

attribench.result.InsertionResult(...)

This class serves as a simple wrapper class for Insertion results.

attribench.result.ImpactCoverageResult(...)

Represents results from running the ImpactCoverage metric.

attribench.result.InfidelityResult(...)

Represents results from running the Infidelity metric.

attribench.result.MaxSensitivityResult(...)

Represents results from running the Max-Sensitivity metric.

attribench.result.MinimalSubsetResult(...)

Represents results from running the MinimalSubset metric.

attribench.result.SensitivityNResult(...)

Represents results from running the Sensitivity-N metric.

Data

attribench.data.IndexDataset(dataset)

Wraps a dataset to return the index of the sample as well.

attribench.data.AttributionsDataset(samples)

Represents a dataset containing attributions for a set of samples and attribution methods.

attribench.data.HDF5Dataset(path)

Dataset stored in a HDF5 file.

Masking

attribench.masking.Masker()

Base class for all maskers.

attribench.masking.image.ImageMasker(...)

Abstract base class for all image maskers.

attribench.masking.image.BlurringImageMasker(...)

Image masker that masks pixels or features by replacing them with a blurred version of the image.

attribench.masking.image.ConstantImageMasker(...)

Image masker that masks pixels or features by replacing them with a given constant value.

attribench.masking.image.RandomImageMasker(...)

Image masker that masks images with normally distributed random noise, with a given standard deviation.

attribench.masking.image.SampleAverageImageMasker(...)

Image masker that masks pixels or features by replacing them with the average value in the corresponding image.

attribench.masking.TabularMasker([mask_value])

Parameters:

Plot

attribench.plot.Plot(dfs)

Abstract base class for all plots.

attribench.plot.WilcoxonSummaryPlot(dfs)

Summary plot for Wilcoxon tests.

attribench.plot.InterMetricCorrelationPlot(dfs)

Heatmap showing Spearman correlations between metrics.

attribench.plot.InterMethodCorrelationPlot(dfs)

Heatmap showing Spearman correlations between methods.

attribench.plot.ConvergencePlot(df)

Line plot of the median values of a given metric vs the number of samples.

attribench.plot.KrippendorffAlphaPlot(dfs)

Bar plot of Krippendorff's alpha for each metric.

attribench.plot.ClusterPlot(dfs)

Clustermap of the median values of the metrics and methods.

attribench.plot.MADRatioPlot(dfs)

Bar plot of the MAD (Median Absolute Deviation) ratio for each metric.

attribench.plot.WilcoxonBarPlot(dfs)

Alternative to WilcoxonSummaryPlot.

Other

attribench.ModelFactory()

Basic interface for a callable that returns a model.

attribench.BasicModelFactory(base_model)

Basic implementation of a ModelFactory that just returns a deep copy of a given model.

attribench.MethodFactory(config_dict)

This class accepts a config dictionary for attribution methods in its constructor, and will return a dictionary of ready-to-use AttributionMethod objects when called with a model (nn.Module) as argument.

attribench.AttributionMethod(model, **kwargs)

Wrapper class for attribution methods.