convert_model
Description
Converts a TensorFlow model based on the user-defined quantization factors into a model serving for both accuracy simulation in the TensorFlow environment and inference on Ascend AI Processor.
Constraints
- The user model must match the quantization factor record file. For example, if the Conv+BN+Scale composite is fused before computation to generate the quantization factors, the Conv+BN+Scale composite in the Caffe model to be converted also needs to be fused in advance.
- The format and content of the quantization factor record file must comply with the AMCT requirements defined in Record Files.
- AMCT quantizes the following layers: Conv2D, MatMul, DepthwiseConv2dNative (dilation = 1), Conv2DBackpropInput (dilation = 1), and AvgPool.
- This API supports the fusion of the Conv+BN, Depthwise_Conv+BN and Group_conv+BN fusion structures in the user model. You can configure whether to perform fusion layer by layer.
- Only the original floating-point model can be input for adaptation. You cannot insert custom layers (QuantIfmr, QuantArq, SearchN, AscendQuant, AscendDequant, AscendAntiQuant, and AscendWeightQuant layers) into the quantization tool. The model is adapted.
Prototype
convert_model(pb_model, outputs, record_file, save_path)
Command-Line Options
Parameter |
Input/Return |
Description |
Restriction |
|---|---|---|---|
pb_model |
Input |
Original .pb model file to be adapted. |
A string |
outputs |
Input |
List of output operators of the graph. |
A list. |
record_file |
Input |
Path of the quantization factor record file (.txt) computed by the user. |
A string |
save_path |
Input |
Model save path. Must include the prefix of the model name, for example, ./quantized_model/*model. |
A string |
Returns
None
Outputs
A .pb model file that serves for both accuracy simulation in the TensorFlow environment and offline inference on Ascend AI Processor.
When distillation is performed again, the preceding files output by this API will be overwritten.
Example
1 2 3 4 5 | import amct_tensorflow as amct convert_model(pb_model='./user_model.pb', outputs=["model/outputs"], record_file='./record_quantized.txt', save_path='./quantized_model/model') |