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 5629481dbc79bb34d947a5bfa8e7f611c0647ac3..407d90abf8053d9fd5e4c24b1a52581736d69e04 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日志