Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train CLIP model with own data #1059

Open
yafeng-c opened this issue Jul 9, 2021 · 4 comments
Open

Train CLIP model with own data #1059

yafeng-c opened this issue Jul 9, 2021 · 4 comments

Comments

@yafeng-c
Copy link

yafeng-c commented Jul 9, 2021

Hi,
Thanks for your amazing work.
It's more like a discussion. Anyway, I am trying to train the CLIP model with my own data.

train_samples = []
a loop:
    inp_example = InputExample(texts=[imgdata, textdata], label=scoredata)
    train_samples.append(inp_example)
train_dataloader = DataLoader(train_samples, batch_size=BATCH_SIZE, shuffle=True)

model =  SentenceTransformer('clip-ViT-B-32')

model.fit(train_objectives=[(train_dataloader, train_loss)],
          evaluator=evaluator,
          epochs=num_epochs,
          evaluation_steps=10,
          warmup_steps=warmup_steps,
          output_path=model_save_path)

It can run. But is this correct? By doing so, are all layers retrained? Is it possible to freeze some layers? (I used Tensorflow before, new in Pytorch).

@nreimers
Copy link
Member

Looks good. Only the definition of the loss is missing

@milmin
Copy link

milmin commented Nov 17, 2021

Hi how do we put image data in InputExample? Should we process image data? Because DataLoader does not accept PIL images...

@breadfan
Copy link

Have you got any workable model with this? I can't figure out how to make fine-tuning using images and promts

@tomaarsen
Copy link
Collaborator

Hello @breadfan & others,

I've yet to review this pull request, but examples/unsupervised_learning/CLIP/sample_clip.ipynb from #2390 seems to show how to finetune a CLIP model. It might be helpful for you all. When I have some more time, then I'll review that PR and add the finetuning example to the repository itself.

  • Tom Aarsen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants