Please install and setup AIMET before proceeding further.
- Clone the MobileNetV2 repo
git clone https://github.com/tonylins/pytorch-mobilenet-v2
cd pytorch-mobilenet-v2/
git checkout 99f213657e97de463c11c9e0eaca3bda598e8b3f
- Place model definition under model directory
mkdir ../aimet-model-zoo/zoo_torch/examples/model
mv MobileNetV2.py ../aimet-model-zoo/zoo_torch/examples/model/
- Download Optimized MobileNetV2 checkpoint from Releases and place under the model directory.
- Replace all ReLU6 activations with ReLU
- 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))
- The original MobileNetV2 checkpoint can be downloaded here:
- Optimized MobileNetV2 checkpoint can be downloaded from the Releases page.
- ImageNet can be downloaded here:
- 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>
- 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