Files
openvino/docs/snippets/template_model_transformation.cpp
T

41 lines
1.5 KiB
C++
Raw Normal View History

2023-01-16 11:02:17 +04:00
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
2022-02-23 06:29:03 +03:00
#include "template_model_transformation.hpp"
2022-03-01 09:03:59 +03:00
#include "openvino/cc/pass/itt.hpp"
2021-06-01 10:05:17 +03:00
2022-02-23 06:29:03 +03:00
// ! [model_pass:template_transformation_cpp]
// template_function_transformation.cpp
2020-11-30 15:13:01 +03:00
2022-03-01 09:03:59 +03:00
bool ov::pass::MyModelTransformation::run_on_model(const std::shared_ptr<ov::Model>& f) {
RUN_ON_MODEL_SCOPE(MyModelTransformation);
// Example transformation code
NodeVector nodes;
// Traverse nGraph Function in topological order
2021-05-25 10:32:48 +03:00
for (auto& node : f->get_ordered_ops()) {
// Check that number of input and output ports are equal to 1
if (node->inputs().size() == 1 && node->outputs().size() == 1) {
// Check that input and output shape a fully defined (not dynamic) and number of consumers equal to 1
Input<Node> input = node->input(0);
Output<Node> output = node->output(0);
2021-08-11 09:38:43 +03:00
if (input.get_partial_shape().is_static() && output.get_partial_shape().is_static() &&
output.get_target_inputs().size() == 1) {
nodes.push_back(node);
}
}
}
// Print types and names for collected nodes
2021-05-25 10:32:48 +03:00
for (auto& node : nodes) {
2021-08-11 09:38:43 +03:00
std::cout << "Type: " << node->get_type_info().name << std::endl
<< "Name: " << node->get_friendly_name() << std::endl;
}
// Return false because we didn't change nGraph Function
return false;
}
2022-02-23 06:29:03 +03:00
// ! [model_pass:template_transformation_cpp]