Creating Custom Hef using DFC/Model Zoo

Hey @mzahana

To help you retrain and compile YOLOv8 models (especially segmentation models) with a custom dataset, generating a .hef file, here are answers to each of your questions, along with some detailed steps to guide you through the process:

1. Start/End Node Names in Parsing Step

  • Importance: Yes, specifying the correct start and end node names is important to ensure that the model’s inputs and outputs are mapped correctly during parsing and compilation.
  • How to Find Node Names: You can use tools like Triton, Netron, or ONNX Graph Surgeon (from NVIDIA’s TensorRT) to inspect the model structure and obtain the node names.
    • In Triton, the input name (images) and output names (output0, output1) are commonly used for YOLO models. However, it’s best to verify these by examining the model directly with Netron or similar tools to confirm.
  • Setting Node Names: Use these node names (e.g., images for input, output0 and output1 for outputs) in the parsing step when configuring the Hailo-8 compilation pipeline.

2. YAML File Configuration

  • Purpose: The YAML file provides metadata for the model and specifies details such as the number of classes, input dimensions, and anchor boxes (for object detection models).
  • Custom Modifications:
    • Update the YAML file to match your custom dataset:
      • Classes: Set the num_classes parameter to the number of classes in your dataset.
      • Anchors: Modify anchors if necessary, although for segmentation models, this may be less critical.
      • Input Shape: Ensure the input dimensions align with your custom model.
    • Different YAMLs: The YAML file in Hailo’s model zoo (yolov8n_seg.yaml) may have different settings than the one in Ultralytics’ YOLO repo (yolov8n-seg.yaml). Hailo’s version is often tailored for compatibility with their processing pipeline, so use the Hailo YAML file as a reference, but update it for your specific dataset.

3. --model-script Parameter

  • Definition: The --model-script parameter specifies a Python script that defines custom preprocessing or postprocessing steps needed for your model. This can include data transformations, input/output adjustments, or other custom processing logic that is specific to your model.
  • Need for Custom Models: For custom models, you may need to define a model script if your model’s preprocessing steps differ from the default or if the output format needs modification before use. Ensure this script matches the format and structure required for Hailo’s processing pipeline.

4. Compiling Custom Models with Hailo-8

  • Training and Export:
    1. Train or fine-tune your YOLOv8 model using Ultralytics’ YOLOv8 framework.
    2. Export the trained model to ONNX format.
  • Compilation with Hailo AI Suite:
    1. Place the ONNX model in the Hailo AI Suite Docker environment.
    2. Use the hailo_model_optimizer tool to optimize the model, providing the modified YAML file and --model-script if applicable.
    3. Run the hailo_model_compiler to compile the model into a .hef file. Ensure you specify the correct start and end nodes here.

Example YAML and Compilation Command

  • Modify the YAML for your model:
    num_classes: <your_number_of_classes>
    input_shape: [640, 640]  # Adjust according to your model
    # other parameters as needed
    
  • Example command to compile:
    hailo_model_optimizer --model my_model.onnx --yaml-path custom_model.yaml --model-script custom_script.py
    hailo_model_compiler --hef-path my_model.hef --model-optimized custom_model_optimized.hmo
    

Troubleshooting Tips

  • Node Errors: If errors persist related to node names, verify that you are using the correct start and end nodes.
  • Community and Documentation: Check Hailo’s documentation and community forums, as updates or additional resources may be available for custom compilation workflows.

These steps should help you compile a custom YOLOv8 segmentation model for use with Hailo-8. If you have further questions, please feel free to reach out!

1 Like