braindecode.visualization.random_target#
- braindecode.visualization.random_target(target, n_classes, generator=None)[source]#
Return labels uniformly sampled from
{0, ..., n_classes-1} \ target.For each entry of
targetpick a different class at random. Used in the label-randomization sanity check: query the trained model’s attribution method with the wrong target and check whether the resulting map differs from the correct-target map. Accepts a Python int, NumPy array, or torch tensor and returns the same kind of object on the same device.- Parameters:
target (int, numpy.ndarray, or torch.Tensor) – True class index/indices.
n_classes (int) – Total number of classes; must be at least 2.
generator (numpy.random.Generator, optional) – Source of randomness. Defaults to
numpy.random.default_rng().
- Return type:
Same type as
target(orintwhentargetis a scalar).