代码拉取完成,页面将自动刷新
中文|English
此链接提供KGAT TensorFlow模型在NPU上离线推理的脚本和方法
此案例仅为您学习Ascend软件栈提供参考,不用于商业目的。
在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败。
Conditions | Need |
---|---|
CANN版本 | >=5.0.3 |
芯片平台 | Ascend310/Ascend310P3 |
第三方依赖 | 请参考 'requirements.txt' |
git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git
cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/recommendation/KGAT_for_ACL
请自行下载测试数据集,详情见: amazon-book
获取pb模型, 详情见: pb
编译推理应用程序, 详情见: xacl_fmk
KGAT
环境变量设置
请参考说明,设置环境变量
预处理
python3 offline_inference/data_preprocess.py
在Model/input_bin目录中生成bin文件
Pb模型转换为om模型
atc --model=KGAT_tf.pb --framework=3 --output=ID1376_KGAT_tf_gpu --soc_version=Ascend310 --input_shape="Placeholder:2048;Placeholder_1:24915;Placeholder_4:3" --log=info
将转换后的om文件放入Model目录
运行推理与后处理
python3 offline_inference/xacl_inference.py
2021-08-19 19:38:24.124 - I - [XACL]: Om model file is: ID1376_KGAT_tf_gpu.om
2021-08-19 19:38:24.124 - I - [XACL]: Input files are: input_bin/input1,input_bin/input2,input_bin/input3
2021-08-19 19:38:24.124 - I - [XACL]: Output file prefix is: output_bin/kgat_output_bin
2021-08-19 19:38:24.124 - I - [XACL]: Input type is director
2021-08-19 19:38:24.272 - I - [XACL]: Init acl interface success
2021-08-19 19:38:24.866 - I - [XACL]: Load acl model interface success
2021-08-19 19:38:24.866 - I - [XACL]: Create description interface success
2021-08-19 19:38:24.866 - I - [XACL]: The input file: input_bin/input1/users_00000.bin is checked
2021-08-19 19:38:24.866 - I - [XACL]: The input file: input_bin/input2/pos_items_00000.bin is checked
2021-08-19 19:38:24.866 - I - [XACL]: The input file: input_bin/input3/node_dropout_00000.bin is checked
...
2021-08-19 19:41:22.743 - I - [XACL]: The input file: input_bin/input1/users_00033.bin is checked
2021-08-19 19:41:22.743 - I - [XACL]: The input file: input_bin/input2/pos_items_00033.bin is checked
2021-08-19 19:41:22.743 - I - [XACL]: The input file: input_bin/input3/node_dropout_00033.bin is checked
2021-08-19 19:41:22.743 - I - [XACL]: Create input data interface success
2021-08-19 19:41:22.782 - I - [XACL]: Create output data interface success
2021-08-19 19:41:27.705 - I - [XACL]: Run acl model success
2021-08-19 19:41:27.705 - I - [XACL]: Loop 0, start timestamp 1629373282783, end timestamp 1629373287705, cost time 4922.59ms
2021-08-19 19:41:27.914 - I - [XACL]: Dump output 0 to file success
2021-08-19 19:41:27.914 - I - [XACL]: Single batch average NPU inference time of 1 loops: 4922.59 ms 0.20 fps
2021-08-19 19:41:27.914 - I - [XACL]: Destroy input data success
2021-08-19 19:41:28.134 - I - [XACL]: Destroy output data success
2021-08-19 19:41:28.460 - I - [XACL]: Start to finalize acl, aclFinalize interface adds 2s delay to upload device logs
2021-08-19 19:41:30.197 - I - [XACL]: Finalize acl success
2021-08-19 19:41:30.197 - I - [XACL]: 34 samples average NPU inference time of 34 batches: 4931.11 ms 0.20 fps
output_bin
[INFO] 推理结果生成结束
{'precision': array([0.01522007, 0.01111792, 0.00916784, 0.00797109, 0.00710147]), 'recall': array([0.14694857, 0.20585731, 0.2472628 , 0.28113915, 0.30843164]), 'ndcg': array([0.09972443, 0.12063131, 0.13402407, 0.14439348, 0.15252858]), 'hit_ratio': array([0.25184514, 0.34177161, 0.39911603, 0.44301682, 0.47649134]), 'auc': 0.0}
本结果是通过运行上面适配的推理脚本获得的。要获得相同的结果,请按照《快速指南》中的步骤操作。
ascend310 | |
---|---|
precision | [0.01522007, 0.01111792, 0.00916784, 0.00797109, 0.00710147] |
recall | [0.14694857, 0.20585731, 0.2472628 , 0.28113915, 0.30843164] |
ndcg | [0.09972443, 0.12063131, 0.13402407, 0.14439348, 0.15252858] |
hit_ratio | [0.25184514, 0.34177161, 0.39911603, 0.44301682, 0.47649134] |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。