Caffe原始npy数据文件要求:
进入Ascend-cann-toolkit安装目录/ascend-toolkit/latest/tools/operator_cmp/compare目录,执行命令去除in-place,命令行举例如下:
python3 inplace_layer_process.py -i /home/HwHiAiUser/resnet50.prototxt
执行命令后,在/home/HwHiAiUser目录下生成去除in-place的new_resnet50.prototxt文件。
本版本不提供Caffe模型numpy数据生成功能,请自行安装Caffe环境并提前准备Caffe原始数据“*.npy”文件。本文仅提供生成符合精度比对要求的numpy格式Caffe原始数据“*.npy”文件的样例参考。
为输出符合精度比对要求的“*.npy”数据文件,需在推理结束后的代码中增加以下类似代码:
#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”数据文件。