robustness.tools.helpers module

robustness.tools.helpers.has_attr(obj, k)

Checks both that obj.k exists and is not equal to None

robustness.tools.helpers.calc_est_grad(func, x, y, rad, num_samples)
robustness.tools.helpers.ckpt_at_epoch(num)
robustness.tools.helpers.accuracy(output, target, topk=(1, ), exact=False)

Computes the top-k accuracy for the specified values of k

Parameters:
  • output (ch.tensor) – model output (N, classes) or (N, attributes) for sigmoid/multitask binary classification
  • target (ch.tensor) – correct labels (N,) [multiclass] or (N, attributes) [multitask binary]
  • topk (tuple) – for each item “k” in this tuple, this method will return the top-k accuracy
  • exact (bool) – whether to return aggregate statistics (if False) or per-example correctness (if True)
Returns:

A list of top-k accuracies.

class robustness.tools.helpers.InputNormalize(new_mean, new_std)

Bases: sphinx.ext.autodoc.importer._MockObject

A module (custom layer) for normalizing the input to have a fixed mean and standard deviation (user-specified).

forward(x)
class robustness.tools.helpers.DataPrefetcher(loader, stop_after=None)

Bases: object

preload()
class robustness.tools.helpers.AverageMeter

Bases: object

Computes and stores the average and current value

reset()
update(val, n=1)
robustness.tools.helpers.get_label_mapping(dataset_name, ranges)
robustness.tools.helpers.restricted_label_mapping(classes, class_to_idx, ranges)
robustness.tools.helpers.custom_label_mapping(classes, class_to_idx, ranges)