ResNet50V2 is a 50-layer deep convolutional neural network built on residual (skip) connections, which address the vanishing gradient problem and enable training of very deep networks [1]. The V2 variant re-orders the residual block to use pre-activation batch normalization [2]. Given an RGB image, the network returns a vector of 1000 class probabilities over the ImageNet classes [3].
This repository contains the ResNet50V2 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).
This is a quantized and compiled version of tf.keras.applications ResNet50V2 (ImageNet weights), optimized for NXP i.MX 8M Plus, i.MX 93, i.MX 95, and i.MX 952 processors.
This model is a derivative work with the following changes from the original:
tf.keras.applications.resnet_v2.preprocess_input, pixels scaled to the [-1, 1] range).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.Original model available at: tf.keras.applications ResNet50V2.
| Information | Value |
|---|---|
| Input shape | Color image (1, 224, 224, 3), dtype int8 |
| Input example | (Public domain picture) |
| Output shape | Vector of probabilities (1, 1000), dtype int8 - see labels.py for the 1000 ImageNet classes |
| Output example | [[-128, -123, 102, -128, ..., -128]] -> Top class: boxer |
| FLOPS | 6 977 MOPS |
| Number of parameters | 25.6 M |
| File size (int8) | 26 290 072 bytes (assets/quantized_tflite_model/resnet50_quant_int8.tflite) |
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 hardware-independent int8 model is also provided for host (x86) inference and as the input to the
compilers above: assets/quantized_tflite_model/resnet50_quant_int8.tflite. This file is byte-identical to
the i.MX 8M Plus asset (assets/imx8mplus/resnet50_quant_int8.tflite is a symlink to it).
This model inherits all limitations from the original tf.keras.applications ResNet50V2 model. Additional limitations:
The original ResNet50V2 model was trained by its authors (The TensorFlow Authors / tf.keras.applications)
on the ImageNet dataset [3]. NXP did not retrain the model; the ImageNet
pretrained weights distributed with tf.keras.applications are used as-is before quantization.
evaluate.py evaluates the int8 quantized TFLite model's top-1 classification accuracy on the
imagenet_v2/topimages test split (via tensorflow_datasets), running on a host PC (x86) with the LiteRT
CPU runtime, using the hardware-independent model assets/quantized_tflite_model/resnet50_quant_int8.tflite:
python evaluate.py --model assets/quantized_tflite_model/resnet50_quant_int8.tflite --num_images 1000
example.py runs classification on an image on a host PC and prints (and optionally saves) the top-5
predicted ImageNet classes:
# Run on PC:
python example.py --model assets/quantized_tflite_model/resnet50_quant_int8.tflite --input example_input.jpg
To run the model on an i.MX MPU target with the NPU delegates, see the i.MX Machine Learning User Guide.
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/
Provide a directory of ImageNet images for calibration via the DATASET_PATH environment variable (a
commercially-useable ImageNetV2 subset is recommended):
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
recipe.sh quantizes the Keras model to int8 TFLite, then compiles/converts it for each target. The
generated files are:
assets/quantized_tflite_model/resnet50_quant_int8.tflite - hardware-independent int8 model, also used
directly on i.MX 8M Plus (assets/imx8mplus/resnet50_quant_int8.tflite)assets/imx93/<VELA_TAG>/resnet50_quant_int8_vela.tflite - Vela-compiled for i.MX 93assets/imx95/<NEUTRON_SDK_VERSION>/resnet50_quant_int8_converted.tflite - Neutron-converted for i.MX 95assets/imx952/<NEUTRON_SDK_VERSION>/resnet50_quant_int8_converted.tflite - Neutron-converted for i.MX 952This model is released under the Apache License 2.0, the same license as the original tf.keras.applications ResNet50V2 model.
If you use this model, please cite both this work and the original model:
@inproceedings{he2016deep,
title={Deep residual learning for image recognition},
author={He, Kaiming and Zhang, Xiangyu and Ren, Shaoqing and Sun, Jian},
booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
pages={770--778},
year={2016}
}
@inproceedings{he2016identity,
title={Identity mappings in deep residual networks},
author={He, Kaiming and Zhang, Xiangyu and Ren, Shaoqing and Sun, Jian},
booktitle={European conference on computer vision},
pages={630--645},
year={2016},
organization={Springer}
}
@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}
}