CoolFace
Modelpublic

SeyedAli/Persian-CLIP

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes8downloads
Model Card

<!-- This model card has been generated automatically according to the information the Trainer had access to. You should probably proofread and complete it, then remove this comment. -->

persian-clip

This model is a fine-tuned version of [](https://huggingface.co/) on an unknown dataset. It achieves the following results on the evaluation set:

  • Loss: 0.7629

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 3e-05
  • trainbatchsize: 32
  • evalbatchsize: 32
  • seed: 42
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lrschedulertype: linear
  • lrschedulerwarmup_steps: 100
  • num_epochs: 5

Training results

Training LossEpochStepValidation Loss
1.40720.121002.1627
1.71460.252001.6432
1.50580.373001.4523
1.38360.494001.4799
1.49460.625001.3101
1.25440.746001.2073
1.19840.867001.1801
1.32430.998001.1652
0.83731.119001.0860
0.86251.2310001.0731
0.7911.3611001.0427
0.89751.4812001.0786
0.77671.613001.0248
0.90411.7314001.0311
0.84741.8515000.9649
0.74351.9816000.9552
0.51262.117000.9909
0.48712.2218000.9188
0.482.3519000.9151
0.47152.4720000.9056
0.4082.5921000.8885
0.49992.7222000.8911
0.51692.8423000.8727
0.35742.9624000.8477
0.27493.0925000.8666
0.27193.2126000.8520
0.27793.3327000.8379
0.34073.4628000.8386
0.2233.5829000.8245
0.26493.730000.8149
0.26983.8331000.7983
0.18633.9532000.7959
0.18314.0733000.7957
0.1724.234000.7963
0.14574.3235000.7879
0.15034.4436000.7794
0.17834.5737000.7788
0.1664.6938000.7753
0.15984.8139000.7673
0.16184.9440000.7629

Framework versions

  • Transformers 4.38.2
  • Pytorch 2.1.2+cu121
  • Datasets 2.10.1
  • Tokenizers 0.15.0

How to use?

python
# Both models generate vectors with 768 dimensions.
from transformers import CLIPVisionModel, RobertaModel, AutoTokenizer, CLIPFeatureExtractor
# download pre-trained models
vision_encoder = CLIPVisionModel.from_pretrained('SeyedAli/Persian-CLIP')
preprocessor = CLIPFeatureExtractor.from_pretrained('SeyedAli/Persian-CLIP')
text_encoder = RobertaModel.from_pretrained('SeyedAli/Persian-CLIP')
tokenizer = AutoTokenizer.from_pretrained('SeyedAli/Persian-CLIP')
# define input image and input text
text = 'something'
image = PIL.Image.open('my_favorite_image.jpg')
# compute embeddings
text_embedding = text_encoder(**tokenizer(text,
                                          return_tensors='pt')).pooler_output
image_embedding = vision_encoder(**preprocessor(image, 
                                                return_tensors='pt')).pooler_output

zero-shot-Image-Classification:

The followings are just some use cases of Persian-CLIP on 25K Unsplash images

  • use pip install -q git+https://github.com/sajjjadayobi/clipfa.git
python
from clipfa import CLIPDemo
import torch
# Both models generate vectors with 768 dimensions.
from transformers import CLIPVisionModel, RobertaModel, AutoTokenizer, CLIPFeatureExtractor
# download pre-trained models
vision_encoder = CLIPVisionModel.from_pretrained('SeyedAli/Persian-CLIP')
preprocessor = CLIPFeatureExtractor.from_pretrained('SeyedAli/Persian-CLIP')
text_encoder = RobertaModel.from_pretrained('SeyedAli/Persian-CLIP')
tokenizer = AutoTokenizer.from_pretrained('SeyedAli/Persian-CLIP')

demo = CLIPDemo(vision_encoder, text_encoder, tokenizer)
demo.compute_text_embeddings(['متن 3' ,'متن 2' ,'متن 1'])
demo.compute_image_embeddings(['my_favorite_image.jpg'])
demo.zero_shot(image_path='my_favorite_image.jpg')