diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/LICENCE b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/LICENCE new file mode 100644 index 0000000000000000000000000000000000000000..68138bbe199d050af8296991a843bf1a5bcf86fd --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Fan Yang + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/README.md b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c7ae99eb778208480730ff53d38aff28e9c13619 --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/README.md @@ -0,0 +1,30 @@ +# DD-NET + +### 关于项目 + +本项目为复现"Make Skeleton-based Action Recognition Model Smaller, Faster and Better"论文算法。 + +论文链接:[paper](https://arxiv.org/pdf/1907.09658.pdf) + +原作者开源代码:[code](https://github.com/fandulu/DD-Net) + +转换后可在Ascend 910运行的代码:[code](https://gitee.com/ascend/ModelZoo-TensorFlow/tree/master/TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow) + +### 模型转换 + +#### h5转pb + +使用'tf.keras.models.save_model'将模型保存为h5文件;运行h5topb.py脚本得到固化的pb文件。 + + +#### pb转om + +使用ATC模型转换工具进行模型转换,命令: +`atc --model=./model.pb --framework=3 --output=./out --soc_version=Ascend310 --input_shape="Input:1,32,105; Input_1:1,32,15,2" --log=info --out_nodes="model_1/dense_2/Softmax:0"` + +### 推理 + +使用msame工具,参考命令: +`/home/HwHiAiUser/AscendProjects/tools/msame/out/msame --model ./out.om --output ./output --outfmt BIN --loop 1 +` + diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/h5topb.py b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/h5topb.py new file mode 100644 index 0000000000000000000000000000000000000000..aa146867d486056052074f45961a4ab287574723 --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/h5topb.py @@ -0,0 +1,68 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# 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. + +import tensorflow as tf +from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2 + +def poses_diff(x): + H, W = x.get_shape()[1],x.get_shape()[2] + x = tf.subtract(x[:,1:,...],x[:,:-1,...]) + x = tf.image.resize(x,size=[H,W]) + return x + +def h5_to_pb(h5_save_path): + model = tf.keras.models.load_model(h5_save_path, compile=False, custom_objects={'poses_diff':poses_diff}) + model.summary() + full_model = tf.function(lambda Input: model(Input)) + full_model = full_model.get_concrete_function([tf.TensorSpec(model.inputs[0].shape, model.inputs[0].dtype), + tf.TensorSpec(model.inputs[1].shape, model.inputs[1].dtype)]) + + # Get frozen ConcreteFunction + frozen_func = convert_variables_to_constants_v2(full_model) + frozen_func.graph.as_graph_def() + + layers = [op.name for op in frozen_func.graph.get_operations()] + print("-" * 50) + print("Frozen model layers: ") + for layer in layers: + print(layer) + + print("-" * 50) + print("Frozen model inputs: ") + print(frozen_func.inputs) + print("Frozen model outputs: ") + print(frozen_func.outputs) + + # Save frozen graph from frozen ConcreteFunction to hard drive + tf.io.write_graph(graph_or_graph_def=frozen_func.graph, + logdir="./pb", + name="model.pb", + as_text=False) #可设置.pb存储路径 + + +h5_to_pb('weights/ddnet.h5') #此处填入.h5路径 \ No newline at end of file diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/model.pb b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/model.pb new file mode 100644 index 0000000000000000000000000000000000000000..f94a31de84a01d661bccc9d66afaa7576c61c88a Binary files /dev/null and b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/model.pb differ diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/modelzoo_level.txt b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/modelzoo_level.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c2153f3493a1d4051230cf3a5f6b72ac3cad795 --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/modelzoo_level.txt @@ -0,0 +1,6 @@ +FuncStatus:OK +PrecisionStatus:POK +GPUStatus:OK +NPUMigrationStatus:POK +AutoTune:NOK +PerfStatus:OK \ No newline at end of file diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/out.om b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/out.om new file mode 100644 index 0000000000000000000000000000000000000000..d69b298435be2fda31fdec8b16e99557da27c0b9 Binary files /dev/null and b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/out.om differ diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/test/X0.bin b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/test/X0.bin new file mode 100644 index 0000000000000000000000000000000000000000..f7fcfa375449dab1c691deee031ecfc204531499 Binary files /dev/null and b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/test/X0.bin differ diff --git a/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/test/X1.bin b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/test/X1.bin new file mode 100644 index 0000000000000000000000000000000000000000..55d4bda72a1ebbe086a5b6c163bc9648a3aa3b07 Binary files /dev/null and b/ACL_TensorFlow/contrib/cv/DD-NET_ID1088_for_TensorFlow/test/X1.bin differ