readme: ---
  language:
  - en
  license: mit
  tags:
  - clip
  - vision
  ---
  
  # CLIP Variants
  
  _The CLIP model was developed by researchers at OpenAI to learn about what contributes to robustness in computer vision tasks. The model was also developed to test the ability of models to generalize to arbitrary image classification tasks in a zero-shot manner. It was not developed for general model deployment - to deploy models like CLIP, researchers will first need to carefully study their capabilities in relation to the specific context they’re being deployed within._
  
  See the original [CLIP Model Card][clip-model-card] for more details on limitations and biases.
  
  This repository holds [OpenAI's CLIP][clip] models converted into many other variants, see below for more details.
  
  ## Disclaimer & License
  
  I haven't done many tests on these conversions. I've briefly tried the float16 versions, which seem very similar to the original float32, however the similarity seems to drop more with the qint8/quint8 versions as expected. I couldn't try qint8 as it seemed unsupported for some operations, but I'm including it for completeness. From a brief test the quint8 version seemed to work fine.
  
  The license for the conversion code is MIT, the license for the models is the same as the original license for the OpenAI models (🤷‍♂️). I have no affiliation with OpenAI.
  
  ## Acknowledgements
  * [OpenAI CLIP][clip]
  * [OpenAI CLIP JavaScript by josephrocca](https://github.com/josephrocca/openai-clip-js)
  * [CLIP-ONNX by Lednik7](https://github.com/Lednik7/CLIP-ONNX)
  * [Exporting a Model from PyTorch to ONNX and Running it using ONNX Runtime](https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html)
  * [imgbeddings by minimaxir](https://github.com/minimaxir/imgbeddings)
  * ... probably more
  
  ## Example
  
  See [example.py](./example.py)
  
  ```
  ❯ python .\example.py
  Loading visual model: models/clip-vit-base-patch32-visual-float16.onnx
  Visual inference ready, input size 224, type tensor(float16)
  Images shape: (2, 3, 224, 224)
  Embeddings shape: (2, 512)
  
  Loading textual model: models/clip-vit-base-patch32-textual-float16.onnx
  Textual inference ready, input size 77, type tensor(int32)
  Texts shape: (14, 77)
  Embeddings shape: (14, 512)
  
  flowers.jpg
    similarity  bar chart    text
  ------------  -----------  ---------------------------------------------------------------
      0.294922  >>>>>>>>     a close up photo of a cherry blossom
      0.267578  >>>>>>>>     cherry blossom
      0.249878  >>>>>>>      flowers
      0.242554  >>>>>>>      a photo taken on a bright and sunny day
      0.228882  >>>>>>       bees
      0.222778  >>>>>>       plant
      0.216187  >>>>>>       a photo taken on a dark and cloudy day
      0.201538  >>>>>>       ruhrgebiet
      0.196655  >>>>>        processing plant
      0.192139  >>>>>        a photo taken at midnight
      0.18689   >>>>>        industry
      0.177856  >>>>>        cars
      0.176636  >>>>>        dogs and cats
      0.111267  >>>          a large industrial plant with many pipes, walkways and railings
  
  heavy-industry.jpg
    similarity  bar chart    text
  ------------  -----------  ---------------------------------------------------------------
      0.336182  >>>>>>>>>>   a large industrial plant with many pipes, walkways and railings
      0.316895  >>>>>>>>>    processing plant
      0.302002  >>>>>>>>>    industry
      0.27417   >>>>>>>>     ruhrgebiet
      0.254883  >>>>>>>      plant
      0.22876   >>>>>>       a photo taken on a dark and cloudy day
      0.219482  >>>>>>       a photo taken on a bright and sunny day
      0.211304  >>>>>>       a photo taken at midnight
      0.198608  >>>>>        cars
      0.190552  >>>>>        flowers
      0.181885  >>>>>        bees
      0.180542  >>>>>        cherry blossom
      0.174438  >>>>>        dogs and cats
      0.14917   >>>>         a close up photo of a cherry blossom
  ```
  
  ## Parameters
  
  The only format supported right now is [Open Neural Network Exchange (ONNX)][onnx].
  
  All the currently available OpenAI models have been converted. Some of the IDs were taken from [Open AI models on Hugging Face](https://huggingface.co/openai), others were made up following the same format.
  
  | Model name | Model ID |
  | --- | --- |
  | RN50 | resnet-50 |
  | RN101 | resnet-101 |
  | RN50x4 | resnet-50x4 |
  | RN50x16 | resnet-50x16 |
  | RN50x64 | resnet-50x64 |
  | RN50 | resnet-50 |
  | RN50 | resnet-50 |
  | RN50 | resnet-50 |
  | ViT-B/16 | vit-base-patch16 |
  | ViT-B/32 | vit-base-patch32 |
  | ViT-L/14 | vit-large-patch14 |
  | ViT-L/14@336px | vit-large-patch14-336 |
  
  As CLIP is a multimodal model, the original models are split into two separate "modes", one for processing images
  and the other for processing text.
  
  | Mode    |
  |---------|
  | visual  |
  | textual |
  
  The models were converted into multiple data types as well.
  
  | Data Type   |
  |-------------|
  | float16     |
  | qint8       |
  | quint8      |
  
  ## Variants
  
  | Path                                                   | Model ID              | Mode    | Data Ty