Skip to main content

Convert_Your_Model

You can get this Notebook on GitHub.

Step 1: Prepare your environment on your host computer

Note: This part of code run on your host computer

The Jupyter Notebook right up have a button like select kernel, then you choose Select Another Kernel, and choose Python Environments, then choose Creat Python Environment and choose Venv, then choose python3.10.

# Here is my hostcomputer information
# Linux PC 6.8.0-45-generic #45~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 11 15:25:05 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

!uname -a
# Here is my python version
# Python 3.10.12

!python -V
# Download hailo model zoo to convert onnx model
try:
! git clone https://github.com/hailo-ai/hailo_model_zoo.git
except Exception as e:
print(f'install error: {e}')

Here we need Hailo DataFlow Compiler to convert our model

Download from official website

1. Register a Hailo account

register_hailo

2. Install Hailo DataFlow Compiler

install_hailo

# Install HailoDFC to compile the model

try:
%pip install ../resource/hailo_dataflow_compiler-3.29.0-py3-none-linux_x86_64.whl -q
print('install successfully')
except:
print('install error')
# Install hailo model zoo

try:
! cd hailo_model_zoo/ && pip install -e . -q
except Exception as e:
print(f'install error: {e}')
# Check if HailoModel Zoo is installed 

! hailomz info mobilenet_v1

Step 2: Using HailoDFC and HailoModelZoo to compile ONNX model to HEF model.

# Copy your onnx model to hailo_model_zoo folder

! cp ../../models/Chapter5/best.onnx ./hailo_model_zoo/
# This command demonstrates converting a model into the HEF format supported by Hailo8L. If you are using Hailo8, please change "Hailo8L" to "Hailo8".
# Your host computer at least have 32GB RAM.

! cd hailo_model_zoo/ && python hailo_model_zoo/main.py compile yolov8n --ckpt best.onnx --hw-arch hailo8l --calib-path /home/jiahao/datasets/train/images --classes 3 --performance
# Move yolov8n.hef to /models/Chapter5

! mv ./hailo_model_zoo/yolov8n.hef ../../models/Chapter5/