bex.loggers package
Module contents
- class bex.loggers.BasicLogger(attributes, path, n_batches=5)
Bases:
objectBasic logger class
- Variables:
metrics – dictionary containing the metrics logged by Bex
This logger logs the metrics computed by the benchmark for a given explainer along with the run configuration and some images of successful counterfactuals. It mostly serves as a base class for custom loggers but it is fully functional.
- Parameters:
attributes (
Dict) – dictionary containing the run configpath – (
string): output path for the logger (seerun())n_batches – (
int, optional): max number of image batches to log
If you wish to test your own explainer on our benchmark use this as a base class and override the
accumulate()andlog()methodsExample
import wandb class WandbLogger(BasicLogger): def __init__(self, attributes, path, n_batches=10): super().__init__(attributes, path, n_batches) wandb.init(project="Bex", dir=self.path, config=self.attributes, reinit=True) def accumulate(self, data, images): super().accumulate(data, images) wandb.log({f"{k}" :v for k, v in data.items()}, commit=True) def log(self): self.metrics = {f"{k}_avg": np.mean(v) for k, v in self.metrics.items()} wandb.log(self.metrics) # create matplotlib figure with the counterfactuals generated fig = self.create_cf_figure() wandb.log({"Counterfactuals": fig}) plt.close() bn = Benchmark() bn.run("dive", logger=WandbLogger)
- accumulate(data, images)
Updates the metric and image history
- Parameters:
data (
Dict) – dictionary containing the metrics compute by Beximages (
Dict) – dictionary containing tensor images from a given batch and their orthogonal counterfactuals