mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #144] NaN on encode_image #125
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#125
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sarahESL on GitHub (Aug 28, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/144
I fine-tuned CLIP on my own dataset and plan to use it as a pretrained network in order to encode images. After loading the model, I get
NaNvalues when usingencode_imageon my images. More interestingly, this happens only since the second batch, so the first batch is alright. I checked the loaded images from the second batch, and they are fine. Any ideas what might be the issue?@jongwook commented on GitHub (Aug 30, 2021):
Not sure. Are you using the encoder in
.eval()mode, and did you usejit=False(now the default) when loading the model? On the ResNet-based models the batchnorm layers might be outputting unintended results in the train mode.Casting the entire model to fp32 by
model.float()or checking if any of the weights have aNaNelement before and after theencode_imagecall might be helpful.You can also try checking the output of each layer to see where the
NaNstarted to happen during encoding.@sarahESL commented on GitHub (Aug 30, 2021):
Thanks. Casting the model to fp32 seems to have solved the problem for now.
@NotNANtoN commented on GitHub (Oct 1, 2021):
@sarahESL Hey, I'm curious about fine-tuning CLIP.
Could you share some details on how many image-text pairs you used and what batch size? Did it work to fine-tune it? I'd appreciate any input! :)
@sarahESL commented on GitHub (Oct 4, 2021):
@NotNANtoN Hey, sure. I used more than 60k image-text pair with batchsizes of 16, 32, 64. Yes, the finetuning worked. I was getting
NaNs on encoding images in test phase, but then casting the model to fp32 bymodel.float()worked, as suggested by @jongwook.@NotNANtoN commented on GitHub (Oct 11, 2021):
Hi Sarah, thanks a lot! That's great to hear. The dataset and batch size both seem to be of a manageable size.
@sarahESL commented on GitHub (Jun 6, 2022):
Just wanted to document that this issue happens on
encode_textas well and casting to fp32 is still the fix.