Open tommying opened 1 year ago
same question.Revisiting Reverse Distillation 's code use the same loss function . so puzzled
same question.Revisiting Reverse Distillation 's code use the same loss function . so puzzled this issue have been discussed in the paper "ReContrast: Domain-Specific Anomaly Detection via Contrastive Reconstruction" (accepted by NIPS)
Hi there!
The paper states that "we calculate their vector-wise cosine similarity loss along the channel axis and obtain a 2-D anomaly map M(WxK)", but the code uses
loss += torch.mean(1-cos_loss(a[item].view(a[item].shape[0],-1), b[item].view(b[item].shape[0],-1)))
. It seems that the loss value is calculated when the matrix is flattened to a single vector.Does the loss function need the formula 1 given in the paper to obtain a 2D anomaly map Mk? Like this:
sim_map = 1 - F.cosine_similarity(a[item], b[item])
loss += (sim_map.view(sim_map.shape[0],-1).mean(-1)).mean()
I think calculating the loss value in this way is consistent with the paper!
However, training the model in this way can lead to a decrease in accuracy. For example, the carpet dataset only achieved an image-level AUC of 92.3%. To eliminate the possibility of slow model convergence, we set the epoch to 1000, but still obtained the same result. (The code only has one modification in the loss function.)
So, the formula provided in the paper cannot achieve the performance reported in the paper? I'm very confused about why this happens.
Looking forward to your reply!