Giter Site home page Giter Site logo

Comments (9)

HenryPengZou avatar HenryPengZou commented on July 17, 2024 4

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.

HobbitLong avatar HobbitLong commented on July 17, 2024

My environment:

Python 3.6.9 (default, Nov  7 2019, 10:44:02)
>>> torch.__version__
'1.2.0'

from supcontrast.

HobbitLong avatar HobbitLong commented on July 17, 2024

I will close for now, feel free to reopen

from supcontrast.

BestJuly avatar BestJuly commented on July 17, 2024

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.

HobbitLong avatar HobbitLong commented on July 17, 2024

@BestJuly ,

I added some fix 4 days ago to improve the stability. Can you try again now?

from supcontrast.

BestJuly avatar BestJuly commented on July 17, 2024

@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.

HobbitLong avatar HobbitLong commented on July 17, 2024

@BestJuly,

Ah, nice catch! Just pushed a fix. Thanks for spotting this!

from supcontrast.

shijianjian avatar shijianjian commented on July 17, 2024

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.

shaunakjoshi12 avatar shaunakjoshi12 commented on July 17, 2024

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.

Thanks man you saved my day!

from supcontrast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.