# What does it take to import CLIP into Java?

**URL:** <https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635>\
**Category:** SameDiff\
**Created:** [June 14, 2023, 11:57pm UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635 "2023-06-14T23:57:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kper22020](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kper22020](https://community.konduit.ai/u/kper22020)\
**Post date:** [June 14, 2023, 11:57pm UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635/1 "2023-06-14T23:57:23Z")

</div>

Hi,

I would like to convert the CLIP (Contrastive Language-Image Pre-Training) model, so that it can be used in a Java program for zero-shot image classification. I not familiar with the dl4j ecosystem as I am with python and pytorch, so this question is also a question of what tools I should look more into. I have some Java experience.

I wonder if I can somehow convert the model into ONNX as an intermediate, then convert it into DL4J. I’ve heard there is no existing way to import a transformer model, and since CLIP uses a vision transformer, I’m wondering if that affects this or makes this difficult; as long as it is not impossible or prohibitively time-consuming I am willing to try it. Does anyone else have experience in this kind of thing? Or tell me what steps can I take to achieve this goal? Thank you in advance!

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 15, 2023, 12:12am UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635/2 "2023-06-15T00:12:19Z")

</div>

@kper22020 can you point to a model you want to import? I can take it for a spin and see what’s needed. Either TF, keras or, onnx format is fine.

---

<div class="post-metadata">

**Author:** ![kper22020](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kper22020](https://community.konduit.ai/u/kper22020)\
**Post date:** [June 15, 2023, 12:36am UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635/3 "2023-06-15T00:36:38Z")

</div>

Thank you for the reply! I am referring to the model mentioned in the CLIP github repository: [GitHub - openai/CLIP: CLIP (Contrastive Language-Image Pretraining), Predict the most relevant text snippet given an image](https://github.com/openai/CLIP)

Specifically, the model and preprocessors corresponding to the checkpoint `ViT-L/14` is what I’m hoping to import.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 15, 2023, 3:04am UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635/4 "2023-06-15T03:04:35Z")

</div>

@kper22020 can you point me to an onnx model? There’s an example of how to do this with just pytorch here:

> <https://github.com/deeplearning4j/deeplearning4j/blob/master/contrib/omnihub/src/omnihub/frameworks/pytorch.py>

There’s also: [Export to ONNX](https://huggingface.co/docs/transformers/serialization)

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [June 15, 2023, 8:43am UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635/5 "2023-06-15T08:43:35Z")

</div>

note that you’ll also need to port the tokenizer, which isn’t directly importable that way

---

<div class="post-metadata">

**Author:** ![kper22020](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kper22020](https://community.konduit.ai/u/kper22020)\
**Post date:** [June 15, 2023, 8:58pm UTC](https://community.konduit.ai/t/what-does-it-take-to-import-clip-into-java/2635/6 "2023-06-15T20:58:08Z")

</div>

@agibsonccc @treo Sorry I haven’t gotten this far, I’ll check out how to export the model and the tokenizer in an onnx format then,
