save_quant_retrain_model
Description
Saves a retrained model to a model that can be used for accuracy simulation and for inference on the Ascend AI Processor.
Restrictions
None
Prototype
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/Return |
Description |
Restrictions |
---|---|---|---|
retrained_model_file |
Input |
Retrained Caffe model definition file (.prototxt). |
A string. Layers for inference in retrained_model_file. The settings in LayerParameter 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 retrained Caffe model (.caffemodel). |
A string. |
save_type |
Input |
Type of the model to save:
|
A string. |
save_path |
Input |
Model save path. Must be prefixed with the model name, for example, ./quantized_model/*model*. |
A string. |
scale_offset_record_file |
Input |
Quantization factor file. |
A string. (Initialized to None by default.) |
config_file |
Input |
Detailed retrain configuration file. |
A string. (Initialized to None by default.) |
Returns
None
Outputs
- Outputs a model for accuracy simulation in the Caffe environment and its weight file, with names containing the fake_quant keyword.
- Outputs a deployable model file and its model weight file, with names containing the deploy keyword. The model can be deployed on the Ascend AI Processor after being converted by the ATC tool.
Example
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 retrain layers, 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)