Skip to content

Latest commit

 

History

History
69 lines (64 loc) · 2.46 KB

MobilenetV2.md

File metadata and controls

69 lines (64 loc) · 2.46 KB

PyTorch-MobileNetV2

Setup AI Model Efficiency Toolkit (AIMET)

Please install and setup AIMET before proceeding further.

Model modifications

  1. Clone the MobileNetV2 repo
git clone https://github.com/tonylins/pytorch-mobilenet-v2
cd pytorch-mobilenet-v2/
git checkout 99f213657e97de463c11c9e0eaca3bda598e8b3f
  1. Place model definition under model directory
mkdir ../aimet-model-zoo/zoo_torch/examples/model
mv MobileNetV2.py ../aimet-model-zoo/zoo_torch/examples/model/
  1. Download Optimized MobileNetV2 checkpoint from Releases and place under the model directory.
  2. Replace all ReLU6 activations with ReLU
  3. Following changes has been made or appended in original model definition for our suite
  • Change line #87 as follows in MobileNetV2.py
self.last_channel = int(last_channel * width_mult) if width_mult > 1.0 else last_channel
  • Change line #91 as follows in MobileNetV2.py
output_channel = int(c * width_mult)
  • Change line #104 as follows in MobileNetV2.py
self.classifier = nn.Sequential(
            nn.Dropout(dropout),
            nn.Linear(self.last_channel, n_class),
        )
  • Change line #110 as follows in MobileNetV2.py
x = x.squeeze()
  • Append line #100 as follows in MobileNetV2.py
self.features.append(nn.AvgPool2d(input_size // 32))

Obtaining model checkpoint and dataset

Usage

  • To run evaluation with QuantSim in AIMET, use the following
python eval_mobilenetv2.py \
	--model-path <path to optimized mobilenetv2 checkpoint> \
	--images-dir <path to imagenet root directory> \
	--quant-scheme <quantization schme to run> \
	--default-output-bw <bitwidth for activation quantization> \
	--default-param-bw <bitwidth for weight quantization>     		

Quantization Configuration

  • Weight quantization: 8 bits, asymmetric quantization
  • Bias parameters are not quantized
  • Activation quantization: 8 bits, asymmetric quantization
  • Model inputs are not quantized
  • TF_enhanced was used as quantization scheme
  • Data Free Quantization and Quantization aware Training has been performed on the optimized checkpoint