进入$HOME/Ascend/ascend-toolkit/latest/tools/operator_cmp/compare目录,执行命令去除in-place,命令行举例如下:
python3 inplace_layer_process.py -i /home/user/resnet50.prototxt
执行命令后,在/home/user目录下生成去除in-place的new_resnet50.prototxt文件。
本版本不提供Caffe模型numpy数据生成功能,请自行安装Caffe环境并提前准备Caffe原始数据“*.npy”文件。本文仅提供生成符合精度比对要求的numpy格式Caffe原始数据“*.npy”文件的样例参考。
为输出符合精度比对要求的“*.npy”数据文件,需在推理结束后的代码中增加dump操作,示例代码如下:
#read prototxt file net_param = caffe_pb2.NetParameter() with open(self.model_file_path, 'rb') as model_file: google.protobuf.text_format.Parse(model_file.read(), net_param) # save data to numpy file for layer in net_param.layer: name = layer.name.replace("/", "_").replace(".", "_") index = 0 for top in layer.top: data = net.blobs[top].data[...] file_name = name + "." + str(index) + "." + str( round(time.time() * 1000000)) + ".npy" output_dump_path = os.path.join(self.output_path, file_name) np.save(output_dump_path, data) print('The dump data of "' + layer.name + '" has been saved to "' + output_dump_path + '".') index += 1
增加上述代码后,运行Caffe模型的应用工程,即可生成符合要求的.npy数据文件。
.npy数据文件命名格式为{op_name}.{output_index}.{timestamp}.npy,详细介绍请参见数据格式要求,其中需要确保文件名中的{output_index}字段存在值为0,否则无比对结果,原因是精度比对时默认从第一个output_index为0的数据开始。