MobileNetV2
Overview
MobileNetV2 is a lightweight convolutional neural network designed to run efficiently on mobile devices and embedded systems. Building on the original MobileNet, MobileNetV2 introduces inverted residual blocks with linear bottlenecks [1]. Given a color image, the network returns a vector of per-class probabilities over the 1000 ImageNet classes [2].
This repository contains the MobileNetV2 model quantized to int8 (int8 input, int8 output) 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).
Key Features
- Mobile-optimized architecture using inverted residuals and linear bottlenecks
- 1000-class ImageNet image classification
- Small footprint: ~3.5M parameters, ~608 MOPS
- int8 quantized (int8 input, int8 output) for accelerated NPU inference on NXP i.MX platforms
Model Description
This is a quantized and compiled version of MobileNetV2, optimized for NXP i.MX 8M Plus, i.MX 93, i.MX 95, and i.MX 952 processors.
- Base Model: tensorflow/models - mobilenet (
tf.keras.applications.MobileNetV2, ImageNet weights) - Original Model Authors: Mark Sandler, Andrew Howard, Menglong Zhu, Andrey Zhmoginov, Liang-Chieh Chen (Google / The TensorFlow Authors)
- Original License: Apache-2.0
- Modified by: NXP
Modifications
This model is a derivative work with the following changes from the original:
- Quantization: Converted from the Keras
tf.keras.applications.MobileNetV2model to TensorFlow Lite int8 (int8 input, int8 output) using the TFLite converter, with post-training full-integer quantization. The representative calibration dataset is a subset of ~100 images drawn from a commercially-usable ImageNetV2 subset, resized to 224x224 and normalized to the [0, 1] range (matching the MobileNetV2 preprocessing). - Compilation (i.MX 93): compiled with Vela for the Ethos-U65 NPU,
tags
lf-6.18.20_2.0.0andlf-6.18.37_2.1.0. - Compilation (i.MX 95 / i.MX 952): converted with the eIQ Neutron SDK versions
3.1.3,3.2.1and3.2.3.
Original model available at: https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet.
Model Information
| Information | Value |
|---|---|
| Input shape | Color image (1, 224, 224, 3), dtype int8 |
| Input example | (Public domain picture) |
| Output shape | Vector of probabilities, shape (1, 1000), dtype int8. See labels.py for the 1000 ImageNet class labels. |
| Output example | [[-128, -123, 102, -128, ..., -128]] -> Top class: boxer |
| FLOPS | 608 MOPS (as defined by the original authors, at 224x224 input) |
| Number of parameters | 3.5 M |
| File size (int8) | 3.8 MB (3,991,688 bytes) |
| Source framework | TensorFlow / Keras |
Supported Hardware and Software Configurations
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.20_2.0.0, Neutron SDK v3.1.3 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 | 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 |
The i.MX 8M Plus asset (assets/imx8mplus/mobilenet_v2_quant_int8.tflite) is a symlink to, and therefore
byte-identical to, the hardware-independent int8 model at assets/quantized_tflite_model/mobilenet_v2_quant_int8.tflite.
That hardware-independent model is also provided for host (x86) inference and as the input to the Vela and
Neutron compilers.
Limitations and Biases
This model inherits all limitations from the original MobileNetV2 model. Additional limitations:
- Task scope: 1000-class ImageNet classification only; the model does not perform detection, segmentation or localization.
- Input resolution: The model expects a fixed 224x224 input; images must be resized (and, for the int8 model, requantized) before inference.
- Dataset bias: The model is trained on ImageNet, which is known to under-represent certain geographic regions, demographic groups and object categories; classification quality may vary accordingly.
Training
The original MobileNetV2 model was trained by Google on the ImageNet dataset [2].
NXP did not retrain the model; the weights used in this repository are the standard ImageNet weights from
tf.keras.applications.MobileNetV2.
Evaluation
evaluate.py runs the int8 quantized model (assets/quantized_tflite_model/mobilenet_v2_quant_int8.tflite) on
a subset of the ImageNet-v2 test split, on a host PC with the LiteRT CPU runtime:
# Run on PC:
python evaluate.py -m assets/quantized_tflite_model/mobilenet_v2_quant_int8.tflite --num_images 1000
Download and Run
Running the example
An example of how to use the model is in example.py (run on a PC). Install the dependencies from
requirements.txt first.
# Run on PC:
python example.py -m assets/quantized_tflite_model/mobilenet_v2_quant_int8.tflite -i example_input.jpg
example.py also accepts an optional -o/--output path to write the top-5 predictions as text.
Please refer to the i.MX Machine Learning User Guide for details on how to run the models on each platform.
Regenerating the assets with recipe.sh
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 int8 input and int8 output), 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/mobilenet_v2_quant_int8.tflite- hardware-independent int8 model (used for i.MX 8M Plus viaassets/imx8mplus/mobilenet_v2_quant_int8.tflite, a symlink to this file)assets/imx93/<VELA_TAG>/mobilenet_v2_quant_int8_vela.tflite- Vela-compiled for i.MX 93assets/imx95/<EIQ_NEUTRON_SDK_VERSION>/mobilenet_v2_quant_int8_converted.tflite- Neutron-converted for i.MX 95assets/imx952/<EIQ_NEUTRON_SDK_VERSION>/mobilenet_v2_quant_int8_converted.tflite- Neutron-converted for i.MX 952
License
This model is released under the Apache License 2.0 (see LICENSE), the same license as the original tensorflow/models MobileNetV2 implementation.
Citation
If you use this model, please cite both this work and the original model:
- Mark Sandler, Andrew Howard, Menglong Zhu, Andrey Zhmoginov, Liang-Chieh Chen. "MobileNetV2: Inverted Residuals and Linear Bottlenecks." CVPR 2018. https://arxiv.org/abs/1801.04381
- Deng, Jia, et al. "ImageNet: A large-scale hierarchical image database." 2009 IEEE Conference on Computer Vision and Pattern Recognition. IEEE, 2009.
@inproceedings{sandler2018mobilenetv2,
title={Mobilenetv2: Inverted residuals and linear bottlenecks},
author={Sandler, Mark and Howard, Andrew and Zhu, Menglong and Zhmoginov, Andrey and Chen, Liang-Chieh},
booktitle={2018 IEEE/CVF conference on computer vision and pattern recognition},
pages={4510--4520},
year={2018},
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}
}