save_quant_retrain_model

Function Usage

Inserts operators such as AscendQuant and AscendDequant into the retrained model to generate a fake-quantized model for simulation and a deployable model for deployment.

Constraints

None

Prototype

save_quant_retrain_model(retrained_model_file, retrained_weights_file, save_type, save_path, scale_offset_record_file = None, config_file = None)

Command-Line Options

Option

Input/Return

Description

Restriction

retrained_model_file

Input

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

A string

Restriction: For layers for inference, the settings in LayerParameter in retrained_model_file must meet inference requirements. For example, use_global_stats of the BatchNorm layer must be set to 1.

retrained_weights_file

Input

Weight file of the Caffe model (.caffemodel).

A string

save_type

Input

Type of the model to be saved.

  • Fakequant indicates the storage precision simulation model.
  • Deploy: a deployable model that can be used for inference on Ascend AI Processor.
  • Both indicates that both models are stored.

A string

save_path

Input

Model save path.

Must include the prefix of the model name, for example, ./quantized_model/*model.

A string

scale_offset_record_file

Input

Quantization factor record file.

Data type: string (Initialized to None by default.)

config_file

Input

Quantization configuration file.

Data type: string (Initialized to None by default.)

Return Value

None

Outputs

  • A fake-quantized model for accuracy simulation in the Caffe environment and its weight file, with names containing the fake_quant keyword.
  • A deployable model and its weight file, with names containing the deploy keyword. The model can be deployed on Ascend AI Processor after being converted by the ATC tool.

Examples

1
2
3
4
5
6
from amct_caffe import amct
retrained_model_file =  './pre_model/retrained_resnet50.prototxt'
retrained_weights_file = './pre_model/resnet50_solver_iter_35000.caffemodel'
scale_offset_record_file = './record.txt'
# Insert the API, save the retrained model as a .prototxt model file and a .caffemodel weight file, and generate four files in ./result: model_fake_quant_model.prototxt, model_fake_quant_weights.caffemodel, model_deploy_model.prototxt and model_deploy_weights.prototxt.
amct.save_quant_retrain_model(retrained_model_file, retrained_weights_file, 'Both', './result/model', scale_offset_record_file, config_json_file)