Hi @ptrblck, reading a lot of iterature the OHNM is being suggested as a method to be used with background class (say for object detection). Does it really work? This is my implementation of ohnm where I sort losses from each image from a batch and create a boolean mask for values >top_k:
loss = F.cross_entropy(logits, batch_labels , weight=class_weights, reduction='none') batch_size = loss.shape[0] for i in range(batch_size): i_loss = loss[i] k_per = 0.9 loss_sorted=torch.sort(i_loss.flatten()) loss_len=len(loss_sorted[0]) top_k_index = int(k_per*loss_len) ohnm_thresh = loss_sorted[0][top_k_index] loss_ohnm = i_loss>ohnm_thresh loss[i] = loss[i]*loss_ohnm loss = loss.sum()/class_weights[batch_labels].sum()
My question is, how does OHNM help and should it only be applied on the background?