niteshade.utils.check_num_of_classes

niteshade.utils.check_num_of_classes(y)

Check the number of classes in one hot encoded data.

Supposing data is initially encoded, to attack it needs to be decoded. Then, before outputting it, it needs to be encoded once again and so we require the number of classes in the data. So we feed in this function the initial encoded labela data to deteremine the number of classes.

Parameters

y (np.array, torch.tensor) – labels (encoded)

Returns

number of classes

Return type

num_classes (int)