Comments (9)
One method to avoid exp_logits becoming 0 or having loss = Nan is to normalize your feature vectors before passing it the loss function. Hope it helps you guys!
from supcontrast.
My environment:
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
>>> torch.__version__
'1.2.0'
from supcontrast.
I will close for now, feel free to reopen
from supcontrast.
I also met the same problem in one server (Python 3.7.4, pytorch 1.2.0
) and did not have this problem in another server (Python 3.7.4, pytorch 1.3.0
). I think this may be caused by different settings of environment (but why?).
A strange thing is that for the first iteration, without calculating loss, some extracted features are nan
. I have not figured out why and how to solve. And now I am running on the server which is fine. One solution may be setting the same experimental environment.
from supcontrast.
I added some fix 4 days ago to improve the stability. Can you try again now?
from supcontrast.
@HobbitLong Thank you for your kindness. The problem vanished several days ago even though I do not know why. When I using the newest version of your code, it also runs well.
By the way, I think for the newest version, .cuda()
is missing in main_supcon.py.
from supcontrast.
Ah, nice catch! Just pushed a fix. Thanks for spotting this!
from supcontrast.
To me, the problem lies in:
exp_logits = torch.exp(logits) * logits_mask
log_prob = logits - torch.log(exp_logits.sum(1, keepdim=True))
my exp_logits
runs into 0 occasionally which causing undefined log
results. Thus, I did a simple adding with 1e-20.
from supcontrast.
To me, the problem lies in:
exp_logits = torch.exp(logits) * logits_mask log_prob = logits - torch.log(exp_logits.sum(1, keepdim=True))my
exp_logits
runs into 0 occasionally which causing undefinedlog
results. Thus, I did a simple adding with 1e-20.
Thanks man you saved my day!
from supcontrast.
Related Issues (20)
- The problem about the number of positives in code
- Why use two anchors? HOT 1
- Loss function is not convergent when batch-sizes smaller? HOT 4
- the mean and std of cifar dataset
- File "main_supcon.py", line 270, in main opt = parse_option() File "main_supcon.py", line 94, in parse_option assert opt.degrees is not None AssertionError
- Question about potentially incomplete usage of 'logits_mask' HOT 1
- Is this using resnet50x4 width? HOT 2
- file “main_linear.py”, line103, set_model(opt) ,if torch.cuda.is_available() is false, why model will not load_state_dict(state_dict) HOT 1
- Execution of code for ImageNet code (Moco trick) HOT 1
- loss computation: mean and not sum HOT 4
- CE vs CE + SupCon HOT 2
- Purpose of logits_mask? HOT 2
- NaN loss for no positive pair from SupCon
- Pre-trained model HOT 1
- What mean, std and other datapreprocessing transforms did you use for ImageNet? HOT 1
- Moco trick?
- Code for using the ImageNet pretrained model
- solved
- How to change backbone HOT 1
- about loss_in and loss_out in paper
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supcontrast.