create_quant_retrain_config

Function Usage

Finds all quantizable layers in a graph, creates a quantization configuration file, and writes the quantization configuration of the quantizable layers to the configuration file.

Restrictions

None

Prototype

create_quant_retrain_config(config_file, model_file, weights_file, config_defination=None)

Parameter Description

Option

Input/Return

Meaning

Restriction

config_file

Input

Path of the QAT configuration file, including the file name.

The existing file (if any) in the path will be overwritten upon this API call.

A string

model_file

Input

Definition file of the original Caffe model (.prototxt).

A string

weights_file

Input

Weight file of the original Caffe model (.caffemodel).

A string

config_defination

Input

Simplified quantization configuration file quant.cfg, which is generated from the retrain_config_caffe.proto file.

The retrain_config_caffe.proto file is stored in /amct_caffe/proto/retrain_config_caffe.proto in the AMCT installation path.

For details about the parameters in the retrain_config_caffe.proto file and the generated simplified quantization configuration file quant.cfg, see Simplified QAT Configuration File.

Default: None

A string

Restriction: If None, a QAT configuration file is generated based on the remaining arguments. In other cases, a configuration file in JSON format is generated based on this argument.

Returns

None

Outputs

Outputs: A QAT configuration file in JSON format. (When QAT is performed again, this file output by the API will be overwritten.) The sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
    "version":1,
    "conv1":{
        "retrain_enable":true,
        "retrain_data_config":{
            "algo":"ulq_quantize"
        },
        "retrain_weight_config":{
            "algo":"arq_retrain",
            "channel_wise":true
        }
    },
    "conv2_1/expand":{
        "retrain_enable":true,
        "retrain_data_config":{
            "algo":"ulq_quantize"
        },
        "retrain_weight_config":{
            "algo":"arq_retrain",
            "channel_wise":true
        }
    },
    "conv2_1/dwise":{
        "retrain_enable":true,
        "retrain_data_config":{
            "algo":"ulq_quantize"
        },
        "retrain_weight_config":{
            "algo":"arq_retrain",
            "channel_wise":true
        }
    },
}

Examples

1
2
3
4
5
6
from amct_caffe import amct
retrain_simple = 'retrain/retrain.cfg'
model_file = 'resnet50_train.prototxt'
weights_file = 'ResNet-50-model.caffemodel'
config_json_file = './config.json'
amct.create_quant_retrain_config(config_json_file, model_file, weights_file, retrain_simple)