Fine-tuning CLIP Model with ResNet50x4 Backbone for Hailo-8L Deployment on Raspberry Pi 5

I’m currently working on a project to accelerate a fine-tuned CLIP model using the Hailo-8L on a Raspberry Pi 5. Specifically, I am exploring methods to apply fine-tuning on the CLIP model that uses a ResNet-50x4 backbone, which is available in the Hailo Model Zoo.

Before proceeding further, I wanted to ask the following:

  1. Is there any official guideline or recommended workflow for applying fine-tuning to a CLIP model and deploying it on Hailo-8L?
  2. Are there any Hailo-supported tools, libraries, or Docker environments that facilitate this kind of fine-tuning and model compilation process?

Any guidance, documentation links, or examples would be greatly appreciated. I’m happy to share more about the current setup and use case if helpful.

Hey @20246145,

You’re on the right track with deploying a fine-tuned CLIP model on the Hailo-8L with Raspberry Pi 5. Here’s a detailed breakdown based on official Hailo documentation and tools:


1. Fine-tuning CLIP for Hailo – Is it supported?

Yes, Hailo supports fine-tuning and post-quantization optimization through the Dataflow Compiler (DFC). The general workflow looks like this:

  • Fine-tune your model using PyTorch or TensorFlow.
  • Export the model to ONNX.
  • Use post_quantization_optimization() in the model script to adapt it to your dataset:
post_quantization_optimization(finetune, policy=enabled, learning_rate=0.0001, epochs=8, batch_size=4, dataset_size=4000)

You can also configure specific layers and loss functions depending on your setup.


2. Tools & Environments for Fine-Tuning and Deployment

Use the following:

  • Hailo Model Zoo: Pre-built models, YAML configs, and utilities. Install it in the same virtual environment as the DFC.
    Also For model compilation and optimization.
    Repo: hailo_model_zoo

  • Hailo Dataflow Compiler (DFC): For model compilation and optimization.

  • CLIP on Raspberry Pi Examples: Check out the latest tag in this repo:
    hailo-CLIP

  • AI Software Suite Docker: All tools pre-installed and ready to go.


3. Support for ResNet-50x4 CLIP Backbone

Yes, ResNet-50x4 is supported in Model Zoo v2.14.0. You can fine-tune it, export to ONNX, and compile using hailomz.


Suggested Workflow

  1. Fine-tune the CLIP model using PyTorch on a GPU machine.

  2. Export to ONNX using torch.onnx.export().

  3. Compile with Hailo Model Zoo:

    hailomz compile \
      --ckpt fine_tuned_clip.onnx \
      --calib-path ./calib_images \
      --yaml path/to/clip_resnet50x4.yaml
    
  4. Deploy:Run it in here hailo-CLIP