diff --git a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/README.md b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/README.md index f638d40a54b5ea4cec4066e58bd1b7bc2cd8847e..674435a6932aeed024513d049d5965c6280a9a1c 100644 --- a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/README.md +++ b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/README.md @@ -4,6 +4,8 @@ * TensorFlow 1.15.0 * Python 3.7.0 +## 迁移部分代码[地址](https://gitee.com/ascend/ModelZoo-TensorFlow/pulls/790) + ## 代码及路径解释 ``` smith_ID2025_for_ACL @@ -72,12 +74,15 @@ python3 img2bin.py -i ./input_mask_2.txt -t int32 -o ./out/ ### 6 精度对比 ##### 用OM推理的结果: +``` 得分结果: 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.99707 0.5 0.99707 0.99707 0.5 0.99707 0.99707 0.5 0.5 0.5 0.5 0.5 0.5 0.99707 0.5 0.5 0.5 0.99707 0.5 0.5 0.5 0.99707 0.99707 对应label结果: 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 +``` ##### 用ckpt直接推理的结果: +``` {"predicted_score": "0.5", "predicted_class": "0.0"} {"predicted_score": "0.5", "predicted_class": "0.0"} {"predicted_score": "0.99751484", "predicted_class":"1.0"} @@ -109,4 +114,5 @@ python3 img2bin.py -i ./input_mask_2.txt -t int32 -o ./out/ {"predicted_score": "0.5", "predicted_class": "0.0"} {"predicted_score": "0.5", "predicted_class": "0.0"} {"predicted_score": "0.9975251", "predicted_class": "1.0"} -{"predicted_score": "0.99752605", "predicted_class": "1.0"} \ No newline at end of file +{"predicted_score": "0.99752605", "predicted_class": "1.0"} +``` diff --git a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/atc.sh b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/atc.sh index b7c4167793644ec43779a418451310ad60f384a2..6d15ed595a9391e4fc8e44bbb095124ae9d7ac9f 100644 --- a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/atc.sh +++ b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/atc.sh @@ -1 +1,2 @@ -atc --model=smith.pb --framework=3 --output=pb_res --soc_version=Ascend910 --input_shape="input_ids_1:32,2048;input_mask_1:32,2048;input_ids_2:32,2048;input_mask_2:32,2048" --out_nodes="seq_rep_from_bert_doc_dense/l2_normalize_1:0;Sigmoid:0;Round:0" --log=debug \ No newline at end of file +atc --model=smith.pb --framework=3 --output=pb_res --soc_version=Ascend910 --input_shape="input_ids_1:32,2048;input_mask_1:32,2048;input_ids_2:32,2048;input_mask_2:32,2048" --out_nodes="seq_rep_from_bert_doc_dense/l2_normalize_1:0;Sigmoid:0;Round:0" --log=debug + diff --git a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.py b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.py index 8d8140ab61244f12948a2199b35ea6952b7e9174..beb57e7817e48ebade1569a54c1755dd82793f8d 100644 --- a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.py +++ b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.py @@ -1,9 +1,33 @@ -# -*- coding: utf-8 -*- -""" - Created on 2022/4/21 0:18 - - @Author T.c -""" +# coding=utf-8 +# Copyright 2021 The Google Research Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + from absl import flags from absl import app import tensorflow.compat.v1 as tf @@ -16,17 +40,19 @@ from tensorflow.python.framework import graph_util FLAGS = flags.FLAGS flags.DEFINE_string("dual_encoder_config_file", None, "The proto config file for dual encoder SMITH models.") +flags.DEFINE_string("ckpt_path", None, "The NPU ckpt file.") +flags.DEFINE_string("output_graph", "smith.pb", "The output path of pb file.") -# 指定checkpoint路径 -ckpt_path = "/home/test_user06/tc_workspace/data/result_file/tc_wsp_20220920_V4/model.ckpt-10000" +ckpt_path = FLAGS.ckpt_path +output_graph = FLAGS.output_graph def main(_argv): input_ids_1 = tf.placeholder(tf.int32, shape=(32, 2048), name="input_ids_1") - input_mask_1 = tf.placeholder(tf.int32, shape=(32, 2048), name="input_mask_1") #features["input_mask_1"] + input_mask_1 = tf.placeholder(tf.int32, shape=(32, 2048), name="input_mask_1") input_ids_2 = tf.placeholder(tf.int32, shape=(32, 2048), name="input_ids_2") - input_mask_2 = tf.placeholder(tf.int32, shape=(32, 2048), name="input_mask_2") #features["input_mask_2"] + input_mask_2 = tf.placeholder(tf.int32, shape=(32, 2048), name="input_mask_2") exp_config = utils.load_config_from_file(FLAGS.dual_encoder_config_file, experiment_config_pb2.DualEncoderConfig()) tf.logging.info("*** Features ***") masked_lm_positions_1 = tf.zeros([1]) @@ -55,8 +81,6 @@ def main(_argv): graph = tf.get_default_graph() input_graph_def = graph.as_graph_def() - output_graph = "/home/test_user06/tc_workspace/smith_0927_del_full_dropout_27_NPU.pb" - with tf.Session() as sess: sess.run(tf.global_variables_initializer()) saver = tf.train.Saver() @@ -64,7 +88,7 @@ def main(_argv): output_graph_def = graph_util.convert_variables_to_constants( sess=sess, input_graph_def=input_graph_def, - output_node_names=["seq_rep_from_bert_doc_dense/l2_normalize_1","Sigmoid","Round"]) + output_node_names=["seq_rep_from_bert_doc_dense/l2_normalize_1", "Sigmoid", "Round"]) with tf.gfile.GFile(output_graph, "wb") as f: f.write(output_graph_def.SerializeToString()) diff --git a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.sh b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.sh index f4b954047532cc10c9680406ad533e55d14b8541..077429966cc6cf986cacec58d5b716fe080d6e5d 100644 --- a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.sh +++ b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/ckpt2pb.sh @@ -1 +1 @@ -python3 ckpt2pb.py --dual_encoder_config_file=smith/config/dual_encoder_config.smith_wsp.32.48.pbtxt \ No newline at end of file +python3 ckpt2pb.py --dual_encoder_config_file=smith/config/dual_encoder_config.smith_wsp.32.48.pbtxt --ckpt_path=./model.ckpt-10000 --output_graph=./smith.pb diff --git a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/gen_bin_by_img2bin.sh b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/gen_bin_by_img2bin.sh index a148192ea0e80f03acd22318d4b97694ba08e3d5..7a74ffa30a2ea4313c47066ed3683c36e96a7c94 100644 --- a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/gen_bin_by_img2bin.sh +++ b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/gen_bin_by_img2bin.sh @@ -1,4 +1,5 @@ python3 img2bin.py -i ./input_ids_1.txt -t int32 -o ./out/ python3 img2bin.py -i ./input_ids_2.txt -t int32 -o ./out/ python3 img2bin.py -i ./input_mask_1.txt -t int32 -o ./out/ -python3 img2bin.py -i ./input_mask_2.txt -t int32 -o ./out/ \ No newline at end of file +python3 img2bin.py -i ./input_mask_2.txt -t int32 -o ./out/ + diff --git a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/msame.sh b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/msame.sh index f9f5f37d506474454a8df557824a685fb1580d7b..b6b98334892faa63c9facff86293b852e3ab37c3 100644 --- a/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/msame.sh +++ b/ACL_TensorFlow/contrib/nlp/smith_ID2025_for_ACL/msame.sh @@ -1 +1,2 @@ -./msame --model "pb_res.om" --input "out/out4tmp/input_ids_1.bin,out/out4tmp/input_ids_2.bin,out/out4tmp/input_mask_1.bin,out/out4tmp/input_mask_2.bin" --output "output" --loop 1 --outfmt TXT --debug true \ No newline at end of file +./msame --model "pb_res.om" --input "out/out4tmp/input_ids_1.bin,out/out4tmp/input_ids_2.bin,out/out4tmp/input_mask_1.bin,out/out4tmp/input_mask_2.bin" --output "output" --loop 1 --outfmt TXT --debug true +