NanoDet-m

Overview

NanoDet is a lightweight anchor-free object detection model designed to run in real time on mobile and embedded devices. This repository ships the NanoDet-m-0.5x variant, quantized to int8 and compiled for NXP i.MX platforms.

The model takes a 320x320 RGB image and regresses bounding boxes (4 coordinates) and a per-class confidence score for each anchor. The bounding-box decoding (Generalized Focal Loss distribution) and non-maximum-suppression (NMS) steps are not part of the graph. See example.py for a reference implementation of box decoding and NMS in NumPy.

This repository contains the int8-quantized TFLite model compiled for i.MX 8M Plus, i.MX 93 (Ethos-U65), i.MX 95 and i.MX 952 (eIQ Neutron NPU), and shipped as C byte arrays for i.MX RT1170 and i.MX RT700 running TensorFlow Lite Micro.

Key Features

  • Very small (364 KB int8) and fast anchor-free object detector for 320x320 inputs.
  • Detects the 80 COCO object classes.
  • Modified by NXP to use only the coarsest output stride, so it targets medium-to-large objects while keeping inference and result decoding very fast.
  • Fully quantized int8 model with int8 input and int8 output.
  • Available for i.MX 8M Plus, i.MX 93 (Ethos-U65 NPU), i.MX 95 / i.MX 952 (eIQ Neutron NPU), and as C byte arrays for MCUs running TensorFlow Lite Micro (i.MX RT1170, i.MX RT700).

Model Description

This is a quantized and compiled version of NanoDet-m-0.5x, modified by NXP to keep only the coarsest output stride and to strip the in-graph post-processing.

  • Base Model: NanoDet-m-0.5x
  • Original Model Authors: RangiLyu
  • Original License: Apache-2.0
  • Modified by: NXP

Modifications

This model is a derivative work with the following changes from the original:

  • Graph surgery: a patch (nanodet.patch) keeps only the coarsest output level (stride 32) and strips the in-graph post-processing, so the exported graph produces two raw tensors: class scores and undecoded box distributions. Box decoding and NMS are performed in NumPy in example.py / evaluate.py instead.
  • Format conversion: the original PyTorch model is converted to ONNX, then to OpenVINO, then to a TensorFlow saved model, and finally to TensorFlow Lite.
  • Quantization: full int8 post-training quantization (int8 input, int8 output), using 100 calibration images sampled from the COCO 2017 validation set.
  • Compilation:
    • The i.MX 93 model is compiled with Vela tags lf-6.18.20_2.0.0 and lf-6.18.37_2.1.0, using --accelerator-config ethos-u65-256 --optimise Performance.
    • The i.MX 95 and i.MX 952 models are converted with the eIQ Neutron SDK, versions 3.1.3, 3.2.1 and 3.2.3.
    • The MCU targets (i.MX RT1170, i.MX RT700) are built from a base model exported in NHWC layout without the output permute, then compiled with the eIQ Neutron SDK (i.MX RT700 only) and packaged as C header byte arrays for MCUXpresso SDK 26.09.00.
  • Post-processing outside the graph: confidence thresholding, Generalized Focal Loss box decoding, and NMS are performed in NumPy, not in the TFLite graph.

Because only the coarsest output level is kept, the model cannot detect small objects.

Original model available at: https://github.com/RangiLyu/nanodet.

Model Information

Information Value
Input shape RGB image (1, 320, 320, 3), int8
Input example (Image source, Public domain)
Output shape Tensor of size (10, 10, 80), int8, with per-class scores + tensor of size (10, 10, 32), int8, with undecoded box coordinates. See example.py to decode it.
Output example
FLOPS 158.069 MOPS
Number of parameters 204,179
File size (int8) 364 KB
Source framework PyTorch
Target platform MPUs (i.MX 8M Plus, i.MX 93, i.MX 95, i.MX 952), MCUs (i.MX RT1170, i.MX RT700)

Supported Hardware and Software Configurations

The same information is captured in release_manifest.json.

Asset Runtime Precision HW target BSP & SDK versions Resolutions Link to asset
i.MX 8M Plus Quantized LiteRT INT8 i.MX 8M Plus - 320x320 Download
i.MX 93 Precompiled LiteRT INT8 i.MX 93 BSP lf-6.18.20_2.0.0, VELA_TAG = lf-6.18.20_2.0.0 320x320 Download
i.MX 93 Precompiled LiteRT INT8 i.MX 93 BSP lf-6.18.37_2.1.0, VELA_TAG = lf-6.18.37_2.1.0 320x320 Download
i.MX 95 Precompiled LiteRT INT8 i.MX 95 BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 320x320 Download
i.MX 95 Precompiled LiteRT INT8 i.MX 95 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 320x320 Download
i.MX 95 Precompiled LiteRT INT8 i.MX 95 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 320x320 Download
i.MX 952 Precompiled LiteRT INT8 i.MX 952 BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 320x320 Download
i.MX 952 Precompiled LiteRT INT8 i.MX 952 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 320x320 Download
i.MX 952 Precompiled LiteRT INT8 i.MX 952 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 320x320 Download
i.MX RT1170 C header TensorFlow Lite Micro INT8 i.MX RT1170 MCUXpresso SDK 26.09.00 320x320 Download
i.MX RT700 C header TensorFlow Lite Micro INT8 i.MX RT700 Neutron SDK v3.2.2, MCUXpresso SDK 26.09.00 320x320 Download
i.MX RT700 C header TensorFlow Lite Micro INT8 i.MX RT700 Neutron SDK v3.2.3, MCUXpresso SDK 26.09.00 320x320 Download

The assets/imx8mplus/nanodet_m_0.5x.tflite file is the same model as assets/quantized_tflite_model/nanodet_m_0.5x.tflite (the host-only reference model used for development and for generating the i.MX 93 / 95 / 952 precompiled assets), and assets/quantized_tflite_model_mcu/nanodet_m_0.5x_nopermute_mcu.tflite is the equivalent base model for the MCU targets (NHWC layout, no output permute), used to generate the two C headers above. Neither reference model is meant to be run directly on target; they are listed as kind: reference in release_manifest.json.

Limitations and Biases

  • Because only the coarsest output level (stride 32) is kept, the model cannot detect small objects; it is designed for medium-to-large objects only.
  • Box decoding and NMS are not part of the graph; any integration must reproduce the NumPy logic in example.py / evaluate.py, including the Generalized Focal Loss decoding.
  • The model inherits any class and scene biases present in the COCO dataset (for example, uneven representation of certain object categories, geographies and contexts), which can carry over to detections made with this quantized build.

Training

The model was trained on the COCO dataset [1], which features 80 object classes, by the original NanoDet authors, according to the original source. NXP did not retrain the model; only the output head was modified (coarsest stride only) before quantization.

Evaluation

The quantized int8 model can be evaluated with evaluate.py, which runs the model on a PC against the COCO 2017 validation set and computes COCO bounding-box mAP, with confidence thresholding and NMS applied in NumPy since they are not part of the graph. Because this variant keeps only the coarsest output stride, small objects are not detected, which lowers accuracy relative to the full multi-scale model.

Download and Run

The recipe installs the eIQ Neutron SDK from the NXP eIQ PyPI Distribution Portal. Configure pip once to use it:

python -m pip config --user set global.index https://eiq.nxp.com/repository
python -m pip config --user set global.index-url https://eiq.nxp.com/repository
python -m pip config --user set global.trusted-host eiq.nxp.com
python -m pip config --user set global.extra-index-url https://pypi.org/simple
python -m pip config --user set global.find-links https://eiq.nxp.com/repository/

To regenerate the TFLite model fully quantized in int8 (int8 input, int8 output) and compile it for all supported platforms, run:

bash recipe.sh [VELA_TAG] [NEUTRON_VERSION] [NEUTRON_VERSION_MCU]

An example showing how to run detection on an image is in example.py (run on a PC):

python example.py -m assets/quantized_tflite_model/nanodet_m_0.5x.tflite -i example_input.jpg -o example_output.jpg

To evaluate the model on the COCO 2017 validation set, download the validation images and annotations and run:

python evaluate.py -m assets/quantized_tflite_model/nanodet_m_0.5x.tflite \
    -d PATH/TO/val2017 -a PATH/TO/annotations/instances_val2017.json

See the i.MX Machine Learning User Guide for running the LiteRT models on i.MX 8M Plus, i.MX 93, i.MX 95 and i.MX 952 targets.

MCU targets (TensorFlow Lite Micro)

The model is shipped as C header files holding the model as a byte array to be compiled into the firmware image.

MCU Accelerator Neutron target Directory
i.MX RT1170 Cortex-M7 CPU (no NPU) - assets/rt1170/
i.MX RT700 Neutron-64 NPU imxrt700 assets/rt700/3.2.2/, assets/rt700/3.2.3/

The CPU header is not tied to a toolchain version, so it lives directly under assets/rt1170/. The Neutron header is versioned by the eIQ Neutron SDK used to compile it, hence the assets/rt700/<version>/ subdirectory.

Files:

  • assets/quantized_tflite_model_mcu/nanodet_m_0.5x_nopermute_mcu.tflite - MCU base model
  • assets/rt1170/nanodet_m_0.5x_nhwc_tflite.h + assets/rt1170/nanodet_m_0.5x_nhwc_tflite_info.h
  • assets/rt700/3.2.2/nanodet_m_0.5x_nhwc_nopermute_npu64_tflite.h + assets/rt700/3.2.2/nanodet_m_0.5x_nhwc_nopermute_npu64_tflite_info.h
  • assets/rt700/3.2.3/nanodet_m_0.5x_nhwc_nopermute_npu64_tflite.h + assets/rt700/3.2.3/nanodet_m_0.5x_nhwc_nopermute_npu64_tflite_info.h

The MCU base model is the same network as the MPU one, but exported in NHWC layout without the output permute, so it is a different file from assets/quantized_tflite_model/nanodet_m_0.5x.tflite.

Pre/post-processing constants, from the *_info.h headers:

Constant Value
Input width x height 320 x 320
Input mean / std 128 / 127
Output stride 32
Number of classes 80
Box regression bins 32
Max center priors 100

Runnable examples live in the eIQ Media Processing Pipeline (MPP), not in this repository:

License

This model is released under the MIT License, as stated in the LICENSE file. The original NanoDet model is released under the Apache License 2.0, reproduced in MODEL_LICENSE.

Citation

If you use this model, please cite both this work and the original model:

  • Model implementation: https://github.com/RangiLyu/nanodet
  • [1] Lin, Tsung-Yi, et al. "Microsoft COCO: Common Objects in Context." European Conference on Computer Vision. Springer, Cham, 2014.
@inproceedings{lin2014microsoft,
  title={Microsoft coco: Common objects in context},
  author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James and Perona, Pietro and Ramanan, Deva and Doll{\'a}r, Piotr and Zitnick, C Lawrence},
  booktitle={European conference on computer vision},
  pages={740--755},
  year={2014},
  organization={Springer}
}
Downloads last month
102
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collections including nxp/nanodet-m-imx