From 6e597c6b49690a7bda5d8cc5a6096e07c9259892 Mon Sep 17 00:00:00 2001 From: Varol Burak Aydemir Date: Mon, 4 Apr 2022 14:15:29 -0400 Subject: [PATCH] Fixes the usage of SimCLR loss in README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 05269c8b..72925460 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,15 @@ This repo covers an reference implementation for the following papers in PyTorch ImageNet model (small batch size with the trick of the momentum encoder) is released [here](https://www.dropbox.com/s/l4a69ececk4spdt/supcon.pth?dl=0). ## Loss Function -The loss function [`SupConLoss`](https://github.com/HobbitLong/SupContrast/blob/master/losses.py#L11) in `losses.py` takes `features` (L2 normalized) and `labels` as input, and return the loss. If `labels` is `None` or not passed to the it, it degenerates to SimCLR. +The loss function [`SupConLoss`](https://github.com/HobbitLong/SupContrast/blob/master/losses.py#L11) in `losses.py` takes `features` (L2 normalized) and `labels` as input, and return the loss. If `labels` is `None` or not passed to the it, it degenerates to SimCLR. To use SimCLR loss, temperature and base_temperature must be set to the same value. Usage: ```python from losses import SupConLoss # define loss with a temperature `temp` -criterion = SupConLoss(temperature=temp) +criterionSupContrast = SupConLoss(temperature=temp) +criterionSimCLR = SupConLoss(temperature=temp, base_temperature=temp) # features: [bsz, n_views, f_dim] # `n_views` is the number of crops from each image @@ -29,9 +30,9 @@ features = ... labels = ... # SupContrast -loss = criterion(features, labels) +loss = criterionSupContrast(features, labels) # or SimCLR -loss = criterion(features) +loss = criterionSimCLR(features) ... ```