--- /dev/null
+/*
+ * 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 "RemoveTFIdentityNodeTransform.h"
+
+#include "Dialect/TFDialect.h"
+#include "Dialect/TFNode.h"
+
+#include <set>
+
+namespace moco
+{
+namespace tf
+{
+
+bool RemoveTFIdentityNodeTransform::run(loco::Graph *g)
+{
+ struct Collector final : public moco::tf::TFNodeMutableVisitor<void>
+ {
+ void visit(moco::tf::TFIdentity *node) final
+ {
+ if (node->input() != nullptr)
+ {
+ candidates.insert(node);
+ }
+ }
+
+ void visit(moco::tf::TFNode *) final { return; }
+
+ std::set<moco::tf::TFIdentity *> candidates;
+ };
+
+ Collector collector;
+
+ for (auto node : loco::all_nodes(g))
+ {
+ if (node->dialect() == moco::tf::TFDialect::get())
+ {
+ auto tf_node = dynamic_cast<moco::tf::TFNode *>(node);
+ tf_node->accept(&collector);
+ }
+ }
+
+ for (auto node : collector.candidates)
+ {
+ replace(node).with(node->input());
+ node->input(nullptr);
+ }
+
+ return collector.candidates.size() > 0;
+}
+
+} // namespace tf
+} // namespace moco
--- /dev/null
+/*
+ * 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_REMOVE_TFIDENTITY_NODE_TRANSFORM_H__
+#define __MOCO_TF_REMOVE_TFIDENTITY_NODE_TRANSFORM_H__
+
+#include "Transform.h"
+
+namespace moco
+{
+namespace tf
+{
+
+/**
+ * @brief Use the input of "TFIdentity" node instead
+ *
+ * BEFORE:
+ * [X] -> [TFIdentity] -> [Y]
+ *
+ * AFTER:
+ * [X] -> [Y]
+ * [TFIdentity]
+ *
+ * NOTE This transform does not remove "TFIdentity" node
+ * This transform is identical to RemoveForwardNodeTransform
+ */
+struct RemoveTFIdentityNodeTransform final : public Transform
+{
+ const char *name(void) const final { return "RemoveTFIdentityNodeTransform"; }
+
+ bool run(loco::Graph *g) final;
+};
+
+} // namespace tf
+} // namespace moco
+
+#endif // __MOCO_TF_REMOVE_TFIDENTITY_NODE_TRANSFORM_H__