中文|English
此链接提供GRU4Rec 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/contrib/nlp/GRU4Rec_for_ACL
请自行下载数据集, 并放在data目录下(若目录不存在请在子项目根目录下自行创建),
编译推理程序, 详情见: xacl_fmk 将xacl放到当前文件夹
GRU4Rec
环境变量设置
预处理
python3 xnlp_fmk.py \
--data_dir=./data/REC \
--output_dir=./data/REC \
--predict_batch_size=50 \
--model_name=gru \
--task_name=rec \
--action_type=preprocess
冻结Pb模型
python3 xnlp_fmk.py \
--output_dir=./save/model \
--pb_model_file=./save/model/GRU4Rec_full.pb \
--checkpoint_dir=./save/ckpt/gru_rec \
--predict_batch_size=50 \
--model_name=gru \
--task_name=rec \
--action_type=freeze
**Pb模型转换为om模型 **
python3 xnlp_fmk.py \
--output_dir=./save/model \
--pb_model_file=./save/model/GRU4Rec_full.pb \
--om_model_file=./save/model/GRU4Rec_full.om \
--predict_batch_size=50 \
--soc_version="Ascend310" \
--in_nodes="\"input:50;rnn_state:50,100\"" \
--out_nodes="\"logits:0\"" \
--keep_dtype="./save/model/GRU4Rec_full.txt" \
--model_name=gru \
--task_name=rec \
--action_type=atc
运行推理
python3 xnlp_fmk.py \
--data_dir=./data/REC \
--output_dir=./save/output \
--om_model_file=./save/model/GRU4Rec_full.om \
--predict_batch_size=50 \
--merge_input=False \
--model_name=gru \
--task_name=rec \
--action_type=npu
后处理
python3 xnlp_fmk.py \
--data_dir=./data/LCQMC \
--output_dir=./save/output \
--om_model_file=./save/model/GRU4Rec_full.om \
--predict_batch_size=50 \
--model_name=gru \
--task_name=rec \
--action_type=postprocess
将pb模型转换为pbtxt
python3 xnlp_fmk.py \
--output_dir=./save/model \
--pb_model_file=./save/model/GRU4Rec_full.pb \
--model_name=gru \
--task_name=rec \
--action_type=pbtxt
通过pb模型运行推理
python3 xnlp_fmk.py \
--data_dir=./data/GAD \
--output_dir=./save/output \
--pb_model_file=./save/model/GRU4Rec_full.pb \
--predict_batch_size=50 \
--in_nodes="\"input:50;rnn_state:50,100\"" \
--out_nodes="\"logits:0\"" \
--model_name=gru \
--task_name=rec \
--action_type=cpu
[1] https://arxiv.org/abs/1810.04805
[2] https://github.com/google-research/bert
[3] https://github.com/kyzhouhzau/BERT-NER
[4] https://github.com/zjy-ucas/ChineseNER
[5] https://github.com/hanxiao/bert-as-service
[6] https://github.com/macanv/BERT-BiLSTM-CRF-NER
[7] https://github.com/tensorflow/tensor2tensor
[8] https://github.com/google-research/albert
[9] https://github.com/brightmart/albert_zh
[10] https://github.com/HqWei/Sentiment-Analysis
[11] https://gitee.com/wang-bain/xacl_fmk
[12] https://github.com/brightmart/roberta_zh
[13] https://github.com/dmis-lab/biobert
[14] https://github.com/Songweiping/GRU4Rec_TensorFlow
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。