This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def batch_histogram(data_tensor, num_classes=-1): | |
""" | |
From https://discuss.pytorch.org/t/batched-torch-histc/179741 | |
Computes histograms of integral values, even if in batches (as opposed to torch.histc and torch.histogram). | |
Arguments: | |
data_tensor: a D1 x ... x D_n torch.LongTensor | |
num_classes (optional): the number of classes present in data. | |
If not provided, tensor.max() + 1 is used (an error is thrown if tensor is empty). | |
Returns: |