티스토리 뷰

https://github.com/openai/CLIP

 

GitHub - openai/CLIP: Contrastive Language-Image Pretraining

Contrastive Language-Image Pretraining. Contribute to openai/CLIP development by creating an account on GitHub.

github.com

 

 

CLIP 모델 파인튜닝 해보려니 1 iteration 학습하니까 바로 Loss가 nan이 뜬다.

 

당황해서 이슈 찾아보니 이슈가 있었다.

 

https://github.com/openai/CLIP/issues/40

 

NaN values after a single gradient step · Issue #40 · openai/CLIP

Hi! Using PyTorch 1.7.1, I get NaN values after a single parameter update: import torch import torch.nn as nn import torch.nn.functional as F import clip class Model(nn.Module): def __init__(self):...

github.com

 

 

model 로드하고(이때 jit 옵션 False로 세팅)

 

model = model.float()

 

해주면된다.

 

여기까지가 Nan 문제 해결방법이다.

 

아래는 finetuning시에 팁이다.

 

그리고 model 의 proj 레이어를 None으로 만들어주자

 

model.visual.proj = None

 

해주면된다.

 

이는 contrastive learning 시에 쓰이는 피쳐를 위해 linear projection을 시켜주는 용도로 쓰이는 파라미터이다.

 

내 케이스에서는 transfer learning시에는 None처리해줘야 성능이 더 잘나왔다.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함