Configuring skip_layers to Skip Layers with a Large Accuracy Drop
Use Model Accuracy Analyzer to compare the accuracy of each layer of the original model with that of the quantized model, search for layers with a large accuracy drop, and configure skip_layers to skip these layers during accuracy-based automatic quantization.
- Modify the accuracy-based automatic quantization code by adding the skip_layers configuration to skip the layers that do not support quantization.
The following code example shows that a layer is skipped. To skip multiple layers, separate them with commas (,), for example, skip_layers=['op1','op2','op3'].
config_json_file = './config.json' skip_layers = ['Default/network-DeepLabV3/resnet-Resnet/layer4-SequentialCell/0-Bottleneck/downsample-SequentialCell/0-Conv2d/Conv2D-op311'] batch_num = 1 amct.create_quant_config(config_json_file, model, input_data, skip_layers, batch_num) scale_offset_record_file = os.path.join(TMP, 'scale_offset_record.txt') result_path = os.path.join(RESULT, 'model') - Perform accuracy-based automatic quantization.
- Perform inference again.
If skipping layers that do not support quantization affects the model inference result, adjust the model and then quantize the model again.
Parent topic: Compressing a Model Using the AMCT