From 6599ae0074393eeeb05fb848a21dbfebcf73b440 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 13 Jun 2019 12:50:02 +0900 Subject: [PATCH] [moco/tf] Introduce empty FixPaddingTransform (#3754) This will introduce empty FixPaddingTransform to convert TF padding to loco padding Signed-off-by: SaeHie Park --- contrib/moco/lib/frontend/tf/src/Frontend.cpp | 1 + contrib/moco/lib/frontend/tf/src/Transforms.h | 1 + .../tf/src/Transforms/FixPaddingTransform.cpp | 120 +++++++++++++++++++++ .../tf/src/Transforms/FixPaddingTransform.h | 41 +++++++ .../tf/src/Transforms/FixPaddingTransform.test.cpp | 29 +++++ 5 files changed, 192 insertions(+) create mode 100644 contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.cpp create mode 100644 contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.h create mode 100644 contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.test.cpp diff --git a/contrib/moco/lib/frontend/tf/src/Frontend.cpp b/contrib/moco/lib/frontend/tf/src/Frontend.cpp index 8bf3801..3da978d 100644 --- a/contrib/moco/lib/frontend/tf/src/Frontend.cpp +++ b/contrib/moco/lib/frontend/tf/src/Frontend.cpp @@ -276,6 +276,7 @@ void transform_graph(loco::Graph *graph) // Transforms that run multiple times until there is no transform occured { transforms.emplace_back(stdex::make_unique()); + transforms.emplace_back(stdex::make_unique()); // TODO add more TensorFlow related transformations } diff --git a/contrib/moco/lib/frontend/tf/src/Transforms.h b/contrib/moco/lib/frontend/tf/src/Transforms.h index ea1aedd..5d6e09f 100644 --- a/contrib/moco/lib/frontend/tf/src/Transforms.h +++ b/contrib/moco/lib/frontend/tf/src/Transforms.h @@ -18,6 +18,7 @@ #define __MOCO_TF_TRANSFORMS_H__ #include "Transforms/ClearAnnotTransform.h" +#include "Transforms/FixPaddingTransform.h" #include "Transforms/FixShapeTransform.h" #endif // __MOCO_TF_TRANSFORMS_H__ diff --git a/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.cpp b/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.cpp new file mode 100644 index 0000000..7b7198e --- /dev/null +++ b/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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. + */ + +#include "FixPaddingTransform.h" + +#include + +#include + +namespace +{ + +using namespace moco::tf; + +bool fix_padding(loco::AvgPool2D *node) +{ + // TODO implement this + return false; +} + +bool fix_padding(loco::ConstGen *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::FeatureDecode *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::FeatureEncode *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::Forward *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::MaxPool2D *node) +{ + // TODO implement this + return false; +} + +bool fix_padding(loco::Pull *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::Push *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::ReLU *node) +{ + // Nothing to do with padding + return false; +} + +bool fix_padding(loco::TensorConcat *node) +{ + // Nothing to do with padding + return false; +} + +} // namespace + +namespace moco +{ +namespace tf +{ + +bool FixPaddingTransform::run(loco::Graph *graph) +{ + bool changed = false; + for (auto node : loco::all_nodes(graph)) + { +// clang-format off +#define MOCONODE(TYPE_NAME) \ + if (as(node)) \ + { \ + if (fix_padding(as(node))) \ + changed = true; \ + } \ + else +#include "MocoNodes.lst" +#undef MOCONODE + // clang-format on + { + throw std::runtime_error("Not supported loco::Node type in FixPaddingTransform"); + } + } + + return changed; +} + +} // namespace tf +} // namespace moco diff --git a/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.h b/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.h new file mode 100644 index 0000000..439f333 --- /dev/null +++ b/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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. + */ + +#ifndef __MOCO_TF_FIX_PADDING_TRANSFORM_H__ +#define __MOCO_TF_FIX_PADDING_TRANSFORM_H__ + +#include "Transform.h" + +#include + +namespace moco +{ +namespace tf +{ + +/** + * @brief Fix padding to concrete values for nodes having padding attributes in the graph +*/ +class FixPaddingTransform : public Transform +{ +public: + bool run(loco::Graph *graph) override; +}; + +} // namespace tf +} // namespace moco + +#endif // __MOCO_TF_FIX_PADDING_TRANSFORM_H__ diff --git a/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.test.cpp b/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.test.cpp new file mode 100644 index 0000000..00454da --- /dev/null +++ b/contrib/moco/lib/frontend/tf/src/Transforms/FixPaddingTransform.test.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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. + */ + +#include "FixPaddingTransform.h" + +#include + +#include + +TEST(FixPaddingTransform, ctor) +{ + moco::tf::FixPaddingTransform fptransform; + loco::Graph graph; + + ASSERT_FALSE(fptransform.run(&graph)); +} -- 2.7.4