← Writing

Edge AI · Model deployment

Taking a road classifier from PyTorch to Hailo-8

How I prepared a ResNet-50 wet/dry-road classifier for INT8 edge inference while keeping its training-time image preprocessing intact.

A PyTorch checkpoint is not an edge-deployment artifact. A model can work in a notebook, but an accelerator runtime needs a static graph, representative calibration data, and an input pipeline that behaves exactly like training. This project documents that conversion path for a binary wet/dry-road classifier built on ResNet-50.

Start with the model contract

The export script rebuilds the same architecture used during training: a ResNet-50 backbone with a custom classifier head that maps 2,048 features to 256 and then to two road-condition classes. It loads the trained weights, switches to evaluation mode, and exports a fixed 1 × 3 × 256 × 256 ONNX graph.

That detail matters. The classifier head, input shape, RGB order, resize operation, and normalization are all part of the model. If any one of them changes during deployment, the accelerator may run quickly while no longer running the same computation.

The conversion path

  • PyTorch checkpoint to a static ONNX graph.
  • ONNX graph to Hailo's archive representation through the Dataflow Compiler.
  • Representative road images and a model script to calibrate and optimize the graph for INT8.
  • A compiled Hailo Executable Format file, or HEF, for HailoRT inference on the edge device.

The goal is not to retrain or replace the classifier. It is to produce a quantized deployment artifact that preserves its intended input contract for Hailo-8 hardware.

Normalization is an accuracy safeguard

One of the easiest ways to damage a deployed vision model is to preprocess images differently from the training pipeline. This project uses a Hailo .alls model script to place ImageNet-style RGB normalization directly in the compiled graph. The values are scaled for 0 to 255 image inputs, so the edge runtime can receive raw RGB pixels while the graph applies the normalization that training expected.

Keeping that transformation in the deployment graph makes the boundary explicit. It also removes a fragile duplicate preprocessing step from the host application.

Calibration gives INT8 conversion context

The compiler script gathers road images, resizes them to 256 × 256, and prepares a calibration set of 1,024 images. It then uses Hailo's ClientRunner to translate the ONNX graph, load the normalization script, optimize the model, and compile resnet50_wet_dry.hef.

Calibration is not another training pass. It gives the compiler representative input ranges so it can map the floating-point model into an efficient INT8 representation. That is why the calibration images need to resemble the images the model will receive in practice.

What runs on the Raspberry Pi

The final HEF file is the artifact loaded by HailoRT. The runtime example configures a Hailo device, opens inference streams, sends a resized RGB image through the network, and converts the output scores into a class prediction and confidence.

This repository contains the conversion code and a runtime example, not benchmark logs or an accuracy report. The next step is to evaluate the HEF against a held-out test set and measure end-to-end device latency, including image preprocessing and I/O.

What I learned

Edge AI is mostly interface discipline. The model head, tensor shape, color space, resizing, normalization, and calibration set must agree at every handoff. Once that contract is kept intact, the path from a trained PyTorch model to an accelerator-ready artifact becomes repeatable instead of trial and error.

See the project repository ↗ for the export script, Hailo model script, and compiler workflow.