create_quant_retrain_config
功能说明
根据图的结构找到所有可重训练的层(全连接层(MatMul,transpose_a=False, transpose_b=False,adjoint_a=False,adjoint_b=False),卷积层(Conv2D)、Depthwise卷积层(DepthwiseConv2dNative,dilation为1)、反卷积层(Conv2DBackpropInput,dilation为1)以及平均下采样层Pooling),自动生成重训练配置文件,并将可重训练层的重训练配置信息写入配置文件。
约束说明
无。
函数原型
create_quant_retrain_config(config_file, graph, config_defination=None)
参数说明
参数名 |
输入/返回值 |
含义 |
使用限制 |
---|---|---|---|
config_file |
输入 |
待生成的重训练配置文件存放路径及名称。 如果存放路径下已经存在该文件,则调用该接口时会覆盖已有文件。 |
数据类型:string |
graph |
输入 |
用户传入的待量化模型的tf.Graph图。 |
数据类型:tf.Graph |
config_defination |
输入 |
简易配置文件。 基于retrain_config.proto文件生成的简易配置文件quant.cfg, retrain_config.proto文件所在路径为:昇腾模型压缩工具安装目录/amct_tensorflow/proto/retrain_config.proto。 retrain_config.proto文件参数解释以及生成的quant.cfg简易量化配置文件样例请参见简易重训练配置文件说明。 |
默认值为None。 数据类型:string 当取值为None时,使用输入参数生成配置文件;否则,忽略输入的其他量化参数,根据简易重训练配置文件参数config_defination生成json格式的配置文件。 |
返回值说明
无。
函数输出
输出一个json格式的重训练配置文件(重新执行重训练时,该接口输出的重训练配置文件将会被覆盖)。样例如下:
{ "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 } }, }
调用示例
PATH, _ = os.path.split(os.path.realpath(__file__)) config_path = os.path.join(PATH, 'resnet50_config.json') simple_config = './retrain/retrain.cfg' graph = tf.compat.v1.get_default_graph() amct.create_quant_retrain_config(config_path, graph, simple_config)