in utils/ltr_metrics.py [0:0]
def shot_ood(cls_indices, train_class_count):
if isinstance(cls_indices, torch.Tensor):
cls_indices = cls_indices.detach().cpu().numpy()
elif isinstance(cls_indices, np.ndarray):
pass
else:
raise TypeError('Type ({}) of cls_indices not supported'.format(type(cls_indices)))
num_classes = len(train_class_count)
# print(train_class_count, len(train_class_count))
# print(test_class_count, len(test_class_count))
# print(np.unique(cls_indices))
# print(test_class_count)
# CIFAR10 rho=100: [5000, 2997, 1796, 1077, 645, 387, 232, 139, 83, 50]
# CIFAR100 rho=100: [500, 477, 455, 434, 415, 396, 378, 361, 344, 328, 314, 299, 286, 273, 260, 248, 237, 226, 216, 206,
# 197, 188, 179, 171, 163, 156, 149, 142, 135, 129, 123, 118, 112, 107, 102,
# 98, 93, 89, 85, 81, 77, 74, 70, 67, 64, 61, 58, 56, 53, 51, 48, 46, 44, 42, 40, 38, 36, 35, 33, 32, 30,
# 29, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 15, 14, 13, 13, 12, 12, 11, 11,
# 10, 10, 9, 9, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5]
# if num_classes <= 100: # e.g. On CIFAR10/100
# many_shot_thr = train_class_count[int(0.34*num_classes)]
# low_shot_thr = train_class_count[int(0.67*num_classes)]
# else:
# many_shot_thr=100
# low_shot_thr=20
# print(many_shot_thr, low_shot_thr)
many_shot_thr, low_shot_thr = divide_lt(train_class_count)
many_shot = []
median_shot = []
low_shot = []
for i in range(num_classes):
fp_num = (cls_indices == i).sum()
if train_class_count[i] > many_shot_thr:
many_shot.append(fp_num)
elif train_class_count[i] < low_shot_thr:
low_shot.append(fp_num)
else:
median_shot.append(fp_num)
return np.nanmean(many_shot), np.nanmean(median_shot), np.nanmean(low_shot)