MNasNet is a mobile-hardware-friendly
convolutional neural network discovered by Mobile Neural Architecture Search [1]. Given a color image, the
network returns a vector of per-class probabilities over the 1000 ImageNet classes [2]. This repository ships
the mnasnet-a1-075 variant (depth multiplier 0.75), a lightweight model well suited for edge deployment.
This repository contains the MNasNet-A1 0.75 model quantized to int8 (uint8 input, float32 + int64 outputs) and
compiled for NXP i.MX 8M Plus, i.MX 93, i.MX 95, and i.MX 952 processors. It also contains the scripts used to
regenerate these assets (recipe.sh), an inference example (example.py) and an evaluation script
(evaluate.py).
This is a quantized and compiled version of MNasNet-A1 0.75, optimized for NXP i.MX 8M Plus, i.MX 93, i.MX 95, and i.MX 952 processors.
mnasnet-a1-075 SavedModel)This model is a derivative work with the following changes from the original:
mnasnet-a1-075 Keras SavedModel to TensorFlow Lite int8 (uint8 input,
float32 + int64 outputs) using the TFLite converter, with post-training full-integer quantization. The
representative calibration dataset is a subset of commercially-useable ~100 ImageNetV2 images, fed as raw pixel values in the
[0, 255] range (the SavedModel performs its own input scaling).lf-6.18.20_2.0.0 and lf-6.18.37_2.1.0.3.1.3, 3.2.1 and 3.2.3.3.2.3 only. Older SDK versions
(3.1.3, 3.2.1) fail to convert this model for i.MX 95 due to a known FP32Scale saturation limitation that
was only fixed from SDK 3.2.3 onward (see recipe.sh).Original model available at: https://github.com/tensorflow/tpu/tree/master/models/official/mnasnet.
| Information | Value |
|---|---|
| Input shape | Color image (1, 224, 224, 3), dtype uint8 |
| Input example | (Public domain picture) |
| Output shape | 2 tensors: a vector of probabilities, shape (1, 1000), dtype float32, and a scalar ArgMax class index, dtype int64. example.py selects the probability vector. |
| Output example | [[0., ..., 0.031, 0.449, 0., ...]] -> Top class: boxer |
| FLOPS | 447 MOPS (as defined by the original authors, at 224x224 input) |
| Number of parameters | 2.9 M |
| File size (int8) | 3.3 MB (3,410,880 bytes) |
| Source framework | TensorFlow / Keras |
All models run with the eIQ LiteRT (TensorFlow Lite) runtime and the corresponding NPU delegate (VX for i.MX 8M Plus, Ethos-U for i.MX 93, Neutron for i.MX 95 / i.MX 952). The same information is captured in release_manifest.json.
| Asset | Runtime | Precision | HW target | BSP & SDK versions | Link to asset |
|---|---|---|---|---|---|
| i.MX 8M Plus Quantized | LiteRT | INT8 | i.MX 8M Plus | - | 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 | 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 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 | Download |
Note: unlike the other NXP i.MX classification models in this family, i.MX 95 only has one compiled variant (eIQ Neutron SDK 3.2.3) because older Neutron SDK versions fail to convert this model for i.MX 95 (see Modifications above).
The i.MX 8M Plus asset (assets/imx8mplus/mnasnet-a1-075_uint8_float32.tflite) is a symlink to, and therefore
byte-identical to, the hardware-independent int8 model at
assets/quantized_tflite_model/mnasnet-a1-075_uint8_float32.tflite. That hardware-independent model is also
provided for host (x86) inference and as the input to the Vela and Neutron compilers.
This model inherits all limitations from the original MNasNet-A1 model. Additional limitations:
The original MNasNet-A1 model was trained by Google on the ImageNet dataset [2],
using the procedure described in the
model source. NXP did not retrain the
model; the weights used in this repository are the published mnasnet-a1-075 checkpoint.
evaluate.py runs the int8 quantized model (assets/quantized_tflite_model/mnasnet-a1-075_uint8_float32.tflite)
on a subset of the ImageNet-v2 test split, on a host PC with the LiteRT CPU runtime:
python evaluate.py -m assets/quantized_tflite_model/mnasnet-a1-075_uint8_float32.tflite --num_images 1000
An example of how to use the model is in example.py (run on a PC). Install the dependencies first.
# Run on PC:
python example.py -m assets/quantized_tflite_model/mnasnet-a1-075_uint8_float32.tflite -i example_input.jpg
example.py also accepts an optional -o/--output path to write the top prediction as text.
Please refer to the i.MX Machine Learning User Guide for details on how to run the models on each platform.
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 recreate the TFLite model (quantized int8 with uint8 input and float32 + int64 outputs), run:
bash recipe.sh
Provide a directory of ImageNet images for calibration via the DATASET_PATH environment variable
(default is a placeholder):
DATASET_PATH=/path/to/imagenet bash recipe.sh
The Vela tag and eIQ Neutron SDK version can be passed as positional arguments (defaulting to
lf-6.18.20_2.0.0 and 3.2.3 respectively):
DATASET_PATH=/path/to/imagenet bash recipe.sh lf-6.18.37_2.1.0 3.2.3
The generated files are:
assets/quantized_tflite_model/mnasnet-a1-075_uint8_float32.tflite - hardware-independent int8 model (used
for i.MX 8M Plus via assets/imx8mplus/mnasnet-a1-075_uint8_float32.tflite, a symlink to this file)assets/imx93/<VELA_TAG>/mnasnet-a1-075_uint8_float32_vela.tflite - Vela-compiled for i.MX 93assets/imx952/<EIQ_NEUTRON_SDK_VERSION>/mnasnet-a1-075_uint8_float32_converted.tflite - Neutron-converted
for i.MX 952assets/imx95/<EIQ_NEUTRON_SDK_VERSION>/mnasnet-a1-075_uint8_float32_converted.tflite - Neutron-converted for
i.MX 95 (only produced when the conversion succeeds; see Limitations and Biases)This model is released under the Apache License 2.0 (see LICENSE), the same license as the original tensorflow/tpu MNasNet implementation.
If you use this model, please cite both this work and the original model:
@inproceedings{tan2019mnasnet,
title={Mnasnet: Platform-aware neural architecture search for mobile},
author={Tan, Mingxing and Chen, Bo and Pang, Ruoming and Vasudevan, Vijay and Sandler, Mark and Howard, Andrew and Le, Quoc V},
booktitle={2019 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
pages={2815--2823},
year={2019},
organization={IEEE}
}
@inproceedings{deng2009imagenet,
title={Imagenet: A large-scale hierarchical image database},
author={Deng, Jia and Dong, Wei and Socher, Richard and Li, Li-Jia and Li, Kai and Fei-Fei, Li},
booktitle={2009 IEEE conference on computer vision and pattern recognition},
pages={248--255},
year={2009},
organization={Ieee}
}