From d4d21b29098ab7ed2516764f76a53aa930cef829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BD=E5=8D=83=E4=B8=87=E4=BA=BA=E5=90=BE=E5=BE=80?= =?UTF-8?q?=E7=9F=A3?= <1291632293@qq.com> Date: Fri, 28 Oct 2022 07:35:56 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Slot-Attention=5FID202?= =?UTF-8?q?8=5Ffor=5FACL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep diff --git a/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From ebb5626de91cabb9a9305db6ba8ddecc2c53ea50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BD=E5=8D=83=E4=B8=87=E4=BA=BA=E5=90=BE=E5=BE=80?= =?UTF-8?q?=E7=9F=A3?= <1291632293@qq.com> Date: Fri, 28 Oct 2022 07:36:24 +0000 Subject: [PATCH 2/5] readme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 虽千万人吾往矣 <1291632293@qq.com> --- .../Slot-Attention_ID2028_for_ACL/README.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md diff --git a/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md new file mode 100644 index 000000000..8c16f88f2 --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md @@ -0,0 +1,65 @@ +

概述

+提出了Slot Attention 模块,建立了感知表征 (perceptual representations, 如CNN 输出) 与 slots 之间的桥梁 (Feature map/Grid → Set of slots) + + +- 参考论文: + + @article{locatello2020object, + title={Object-Centric Learning with Slot Attention}, + author={Locatello, Francesco and Weissenborn, Dirk and Unterthiner, Thomas and Mahendran, Aravindh and Heigold, Georg and Uszkoreit, Jakob and Dosovitskiy, Alexey and Kipf, Thomas}, + journal={arXiv preprint arXiv:2006.15055}, + year={2020} +} + +- 参考实现: + + https://github.com/google-research/google-research/tree/master/slot_attention + +- 适配昇腾 AI 处理器的实现: + +https://gitee.com/ascend/ModelZoo-TensorFlow/tree/master/TensorFlow/contrib/cv/Slot-Attention_ID2028_for_TensorFlow + +

原始模型

+ +obs地址:obs://lwr-slot-npu/slottl/newslotmodel.pb + + +步骤一:将转化成IEG.pb +通过代码keras_frozen_graph将ckpt-499000转成pb +ckpt的obs地址:obs://lwr-slot-npu/slottl/ +该目录中以checkpoint开头的四个文件 + + +

pb模型

+ +``` +newslotmodel.pb +``` +obs地址:obs://lwr-slot-npu/slottl/newslotmodel.pb + + +

om模型

+ +转newslotmodel.pb到slotmodel.om + +使用ATC模型转换工具进行模型转换时可以参考如下指令: + +``` +atc --model=./newslotmodel.pb --input_shape="input:64, 128, 128, 3" --framework=3 --output=slotmodel --soc_version=Ascend910A --precision_mode=force_fp32 --op_select_implmode=high_precision +``` + +成功转化成slotmodel.om + +slotmodel.om的obs地址:obs://lwr-slot-npu/slottl/slotmodel.om + + + +

使用msame工具推理

+ +参考 https://gitee.com/ascend/tools/tree/master/msame, 获取msame推理工具及使用方法。 + +使用msame推理工具,参考如下命令,发起推理测试: + +``` +./msame --model "slotmodel.om" --output "./" --outfmt TXT --loop 1 +``` \ No newline at end of file -- Gitee From 7fbc670b9e38985c4f85ed4bc3e7e594bc3c0c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BD=E5=8D=83=E4=B8=87=E4=BA=BA=E5=90=BE=E5=BE=80?= =?UTF-8?q?=E7=9F=A3?= <1291632293@qq.com> Date: Fri, 28 Oct 2022 07:37:29 +0000 Subject: [PATCH 3/5] update ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 虽千万人吾往矣 <1291632293@qq.com> --- .../contrib/cv/Slot-Attention_ID2028_for_ACL/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md index 8c16f88f2..2b7511abe 100644 --- a/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md +++ b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/README.md @@ -24,7 +24,7 @@ https://gitee.com/ascend/ModelZoo-TensorFlow/tree/master/TensorFlow/contrib/cv/S obs地址:obs://lwr-slot-npu/slottl/newslotmodel.pb -步骤一:将转化成IEG.pb +步骤一: 通过代码keras_frozen_graph将ckpt-499000转成pb ckpt的obs地址:obs://lwr-slot-npu/slottl/ 该目录中以checkpoint开头的四个文件 @@ -35,7 +35,7 @@ ckpt的obs地址:obs://lwr-slot-npu/slottl/ ``` newslotmodel.pb ``` -obs地址:obs://lwr-slot-npu/slottl/newslotmodel.pb +pb文件的obs地址:obs://lwr-slot-npu/slottl/newslotmodel.pb

om模型

-- Gitee From 5c1537aab86d29fe1088f9dcc2a4cb5936fc3190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BD=E5=8D=83=E4=B8=87=E4=BA=BA=E5=90=BE=E5=BE=80?= =?UTF-8?q?=E7=9F=A3?= <1291632293@qq.com> Date: Fri, 28 Oct 2022 07:37:41 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20ACL?= =?UTF-8?q?=5FTensorFlow/contrib/cv/Slot-Attention=5FID2028=5Ffor=5FACL/.k?= =?UTF-8?q?eep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep diff --git a/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From fc13d91c35c458bbfd25ec3d5c3c7332b5c17663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BD=E5=8D=83=E4=B8=87=E4=BA=BA=E5=90=BE=E5=BE=80?= =?UTF-8?q?=E7=9F=A3?= <1291632293@qq.com> Date: Fri, 28 Oct 2022 07:38:00 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 虽千万人吾往矣 <1291632293@qq.com> --- .../keras_frozen_graph.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/keras_frozen_graph.py diff --git a/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/keras_frozen_graph.py b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/keras_frozen_graph.py new file mode 100644 index 000000000..9a38dd9e5 --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/Slot-Attention_ID2028_for_ACL/keras_frozen_graph.py @@ -0,0 +1,26 @@ +import tensorflow as tf +from tensorflow.python.framework import graph_util +import model as model_utils + +inputs = tf.placeholder(tf.float32, shape=[64, 128, 128, 3],name='input') # input shape + # create inference graph +resolution = (128, 128) +batch_size=64 +num_slots=7 +num_iterations=3 + +model = model_utils.build_model(resolution, batch_size, num_slots, + num_iterations, model_type="object_discovery") +logit1,logit2,logit3,logit4 = model(inputs, training=False) +print("-----------------------------------------测试完成-------------------------------------------") +saver = tf.train.Saver(max_to_keep=5) +# graph_def = tf.get_default_graph().as_graph_def() + +with tf.Session() as sess: + saver.restore(sess, '/home/disk/checkp/checkpoint.ckpt-499000') + print("---------------------开始转换-------------------------------") + output_graph_def = graph_util.convert_variables_to_constants(sess,sess.graph_def,['model/slot_attention_auto_encoder/Sum']) + print("---------------------转换完成--------------------------") + # print(sess.run(tf.get_default_graph().get_tensor_by_name('model/slot_attention_auto_encoder/Sum:0'))) # 3.0 + with tf.gfile.GFile('./newslotmodel.pb', 'wb') as f: + f.write(output_graph_def.SerializeToString()) # 得到文件:model.pb -- Gitee