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.calc_fadein_eps(epoch, fadein_length, eps)

Calculate an epsilon by fading in from zero.

Parameters:
  • epoch (int) – current epoch of training.
  • fadein_length (int) – number of epochs to fade in for.
  • eps (float) – the final epsilon
Returns:

The correct epsilon for the current epoch, based on eps=0 and epoch zero and eps=eps at epoch fadein_length

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()
robustness.tools.helpers.save_checkpoint(state, is_best, filename)
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)