save_quant_retrain_model

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

Inserts operators such as AscendQuant and AscendDequant into the retrained model and generates a fake-quantized model for accuracy simulation and a deployable model.

Restrictions

None

Prototype

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

Parameters

Parameter

Input/Output

Description

retrained_model_file

Input

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

A string.

Restrictions: 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 (.caffemodel) of the retrained Caffe model.

A string.

save_type

Input

Type of the model to be saved.

  • Fakequant: a model for accuracy simulation.
  • Deploy: a deployable model that can be used for inference on the Ascend AI Processor.
  • Both: both models.

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

File for storing quantization factors.

A string. (Initialized to None by default.)

config_file

Input

Quantization configuration file.

A string. (Initialized to None by default.)

Returns

None

Example

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 this API, and save the quantized model to a .prototxt model file and a .caffemodel weight file. The following files can be found in the ./result directory: 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)

Flush files:

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