create_quant_retrain_config

Applicability

Product

Supported

Atlas A3 training series products/Atlas A3 inference series products

x

Atlas A2 training products/Atlas A2 inference products

x

Atlas 200I/500 A2 inference product

Atlas inference series products

Atlas training products

Description

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

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

Parameters

Parameter

Input/Output

Description

config_file

Input

Path (including the file name) of the QAT configuration file.

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

A string.

model_file

Input

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

A string.

weights_file

Input

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

A string.

config_defination

Input

Simplified configuration file quant.cfg generated based on the retrain_config_caffe.proto file. The *.proto file is stored in /amct_caffe/proto/ under the AMCT installation directory. For details about the parameters in the *.proto file and the generated simplified quantization configuration file quant.cfg, see Simplified QAT Configuration File.

Default: None

A string.

Restrictions: 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

Example

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)

Flush file:

A QAT configuration file in JSON format. (When QAT is performed again, the configuration file output by the API will be overwritten.) The following is an example. For details about the parameters, see Quantization Configuration File.

 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
        }
    },
}