From 12df4a69e7d1be7aacd4d277074cab3adfdd8fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=8E=8E=E8=8E=8E?= Date: Thu, 17 Jun 2021 15:37:25 +0800 Subject: [PATCH] =?UTF-8?q?update=20AscendPytorch=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=8E=A8=E7=90=86=E4=BC=97=E6=99=BAFAQ.md.=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0FAQ16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...347\220\206\344\274\227\346\231\272FAQ.md" | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git "a/AscendPytorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272FAQ.md" "b/AscendPytorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272FAQ.md" index 5629481..407d90a 100644 --- "a/AscendPytorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272FAQ.md" +++ "b/AscendPytorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272FAQ.md" @@ -172,7 +172,7 @@ ATC run success, welcome to the next use. W11001: High-priority service of op[PartitionedCall_AvgPool_45_2] is invalid, low-priority service is used. It can work normally but may affect performance. W11001: High-priority service of op[PartitionedCall_AvgPool_52_6] is invalid, low-priority service is used. It can work normally but may affect performance. ``` -(2)output_node输出节点类型更改为float16 +(2)output_node输出节点类型更改为float16 atc转换时指定输出节点类型为float16 ``` atc --framework=5 --model=./ICNet.onnx --output=ICNet_bs1 --out_nodes="Resize_317:0" --output_type=FP16 --input_format=NCHW --input_shape="actual_input_1: 1,3,1024,2048" --log=debug --soc_version=Ascend310 @@ -193,6 +193,41 @@ atc --framework=5 --model=./ICNet.onnx --output=ICNet_bs1 --out_nodes="Resize_31 export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH export ASCEND_OPP_PATH=${install_path}/opp ``` + +### FAQ16、离线推理后处理脚本适配 + 对于一些图像分类的模型,后处理脚本都是通用的;而有些模型(比如分割类)是没有后处理脚本的,需要读者自行适配。 +(1)源码中包含在线推理脚本(如evaluate.py)或测试类脚本(如test.py) +基于这两个脚本适配,一般脚本中都包含类似的model语句 +``` +outputs = model(image) +``` +benchmark离线推理得到的./result/dumpOutput_device0/数据就可以理解为在线推理的model(image)步骤,适配过程就是从./result/dumpOutput_device0/中按照对应的名字将数据读取出来,适配代码参考如下: +``` +outputs = self.file2tensor(annotation_file) + +# 生成的是bin文件 +def file2tensor(self, annotation_file): + + filepath = annotation_file + '_1.bin' + size = os.path.getsize(filepath) + res = [] + L = int(size/4) #由于需要的是float32类型,所以按照4字节读取;根据实际情况按字节读取 + binfile = open(filepath, 'rb') + for i in range(L): + data = binfile.read(4) + num = struct.unpack('f', data) + res.append(num[0]) + binfile.close() + + dim_res = np.array(res).reshape(1,19,1024,2048) #转换为对应的shape,可通过在线推理打印outputs的shape获取到 + tensor_res = torch.tensor(dim_res, dtype=torch.float32) + print(filepath, tensor_res.dtype, tensor_res.shape) + + return tensor_res +``` +(2)如上的文件都没有,可以参考训练过程的validation步骤进行适配,适配方法同上。 + + 2. 更新最新的推理包run包 3. 打印host日志 -- Gitee