ResNet50V2

Overview

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).

Key Features

  • Deep residual architecture with pre-activation bottleneck blocks.
  • 1000-class ImageNet image classification.
  • ~25.6M parameters, ~6 977 MOPS.
  • Fully quantized int8 model (int8 input, int8 output) for accelerated NPU inference on NXP i.MX platforms.

Model Description

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.

  • Base Model: tf.keras.applications ResNet50V2 (ImageNet weights)
  • Original Model Authors: Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun (Microsoft Research) / 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 model to TensorFlow Lite int8 (int8 input, int8 output), calibrated on a commercially-useable ImageNetV2 subset (~100 images resized to 224x224 and preprocessed with tf.keras.applications.resnet_v2.preprocess_input, pixels scaled to the [-1, 1] range).
  • Compilation (i.MX 93): compiled with Vela for the Ethos-U65 NPU, tags lf-6.18.20_2.0.0 and lf-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.1 and 3.2.3.

Original model available at: tf.keras.applications ResNet50V2.

Model Information

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)

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 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).

Limitations and Biases

This model inherits all limitations from the original tf.keras.applications ResNet50V2 model. Additional limitations:

  • Task scope: Single-label image classification over the 1000 ImageNet classes only; it does not perform object detection, segmentation, or classification of categories outside the ImageNet label set.
  • Dataset bias: The model is trained on ImageNet, which is known to have geographic and demographic biases in its image sources and category definitions; classification quality may vary accordingly.

Training

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.

Evaluation

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

Download and Run

Running the example

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.

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/

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 93
  • assets/imx95/<NEUTRON_SDK_VERSION>/resnet50_quant_int8_converted.tflite - Neutron-converted for i.MX 95
  • assets/imx952/<NEUTRON_SDK_VERSION>/resnet50_quant_int8_converted.tflite - Neutron-converted for i.MX 952

License

This model is released under the Apache License 2.0, the same license as the original tf.keras.applications ResNet50V2 model.

Citation

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

  • K. He, X. Zhang, S. Ren and J. Sun, "Deep Residual Learning for Image Recognition," Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016. arXiv:1512.03385.
  • K. He, X. Zhang, S. Ren and J. Sun, "Identity Mappings in Deep Residual Networks," European Conference on Computer Vision (ECCV), Springer, 2016. arXiv:1603.05027.
  • J. Deng, W. Dong, R. Socher, L.-J. Li, K. Li and L. Fei-Fei, "ImageNet: A Large-Scale Hierarchical Image Database," 2009 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), IEEE, 2009.
@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}
}
Downloads last month
171
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collections including nxp/resnet50-imx

Papers for nxp/resnet50-imx