Added clone method for ov::Model (#11390)
* Added clone method for ov::Model * Changed python API
This commit is contained in:
parent
8ab5dbade0
commit
80739700ff
|
|
@ -684,12 +684,9 @@ void regclass_graph_Model(py::module m) {
|
|||
:rtype: bool
|
||||
)");
|
||||
|
||||
model.def(
|
||||
"clone",
|
||||
[](ov::Model& self) {
|
||||
return ov::clone_model(self);
|
||||
},
|
||||
R"(
|
||||
model.def("clone",
|
||||
&ov::Model::clone,
|
||||
R"(
|
||||
Return a copy of self.
|
||||
:return: A copy of self.
|
||||
:rtype: openvino.runtime.Model
|
||||
|
|
|
|||
|
|
@ -111,6 +111,9 @@ public:
|
|||
/// Return the op that generates output i
|
||||
std::shared_ptr<ov::Node> get_output_op(size_t i) const;
|
||||
|
||||
/// \brief Clones the original model
|
||||
std::shared_ptr<ov::Model> clone() const;
|
||||
|
||||
/// Model outputs
|
||||
std::vector<ov::Output<ov::Node>> outputs();
|
||||
ov::Output<ov::Node> output();
|
||||
|
|
|
|||
|
|
@ -971,6 +971,10 @@ ov::Output<ov::Node> ov::Model::add_output(const ov::Output<ov::Node>& port) {
|
|||
return result->output(0);
|
||||
}
|
||||
|
||||
std::shared_ptr<ov::Model> ov::Model::clone() const {
|
||||
return ov::clone_model(*this);
|
||||
}
|
||||
|
||||
namespace bs_util {
|
||||
static int64_t get_batch(const ov::Layout& layout, const ov::PartialShape& shape) {
|
||||
auto batch_idx = ov::layout::batch_idx(layout);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <shared_node_info.hpp>
|
||||
#include <test_common.hpp>
|
||||
|
||||
#include "common_test_utils/graph_comparator.hpp"
|
||||
#include "openvino/core/partial_shape.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
|
|
@ -1863,3 +1864,71 @@ TEST(model, incompatible_layout) {
|
|||
verify_ex_set_layout_result_validate({1, 2, 3, 4}, "NDHWC");
|
||||
verify_ex_set_layout_result_validate({1, 2, 3, 4}, "ND...HWC");
|
||||
}
|
||||
|
||||
TEST(model, clone_model_function) {
|
||||
auto arg0 = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::PartialShape{1, 3, 3, 3});
|
||||
arg0->set_friendly_name("data");
|
||||
arg0->get_output_tensor(0).set_names({"input1"});
|
||||
|
||||
auto arg1 = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 3, 3});
|
||||
arg1->set_friendly_name("data1");
|
||||
arg1->get_output_tensor(0).set_names({"input2", "data1"});
|
||||
|
||||
auto concat = std::make_shared<ov::opset8::Concat>(ov::NodeVector{arg0, arg1}, 1);
|
||||
concat->set_friendly_name("concat");
|
||||
concat->get_output_tensor(0).set_names({"concat_t"});
|
||||
auto result1 = std::make_shared<ov::opset8::Result>(concat);
|
||||
|
||||
auto shape_of = std::make_shared<ov::opset8::ShapeOf>(concat);
|
||||
shape_of->set_friendly_name("shape_of");
|
||||
shape_of->get_output_tensor(0).set_names({"shape_of_t", "identity"});
|
||||
auto result2 = std::make_shared<ov::opset8::Result>(shape_of);
|
||||
auto model = std::make_shared<ov::Model>(ov::ResultVector{result1, result2}, ov::ParameterVector{arg0, arg1});
|
||||
|
||||
model->validate_nodes_and_infer_types();
|
||||
|
||||
auto input1 = model->input(0);
|
||||
auto input2 = model->input("data1");
|
||||
|
||||
auto cloned_model = ov::clone_model(*model);
|
||||
|
||||
const auto fc = FunctionsComparator::with_default()
|
||||
.enable(FunctionsComparator::ATTRIBUTES)
|
||||
.enable(FunctionsComparator::CONST_VALUES);
|
||||
const auto res = fc.compare(model, cloned_model);
|
||||
EXPECT_TRUE(res.valid) << res.message;
|
||||
}
|
||||
|
||||
TEST(model, clone_model) {
|
||||
auto arg0 = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::PartialShape{1, 3, 3, 3});
|
||||
arg0->set_friendly_name("data");
|
||||
arg0->get_output_tensor(0).set_names({"input1"});
|
||||
|
||||
auto arg1 = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 3, 3});
|
||||
arg1->set_friendly_name("data1");
|
||||
arg1->get_output_tensor(0).set_names({"input2", "data1"});
|
||||
|
||||
auto concat = std::make_shared<ov::opset8::Concat>(ov::NodeVector{arg0, arg1}, 1);
|
||||
concat->set_friendly_name("concat");
|
||||
concat->get_output_tensor(0).set_names({"concat_t"});
|
||||
auto result1 = std::make_shared<ov::opset8::Result>(concat);
|
||||
|
||||
auto shape_of = std::make_shared<ov::opset8::ShapeOf>(concat);
|
||||
shape_of->set_friendly_name("shape_of");
|
||||
shape_of->get_output_tensor(0).set_names({"shape_of_t", "identity"});
|
||||
auto result2 = std::make_shared<ov::opset8::Result>(shape_of);
|
||||
auto model = std::make_shared<ov::Model>(ov::ResultVector{result1, result2}, ov::ParameterVector{arg0, arg1});
|
||||
|
||||
model->validate_nodes_and_infer_types();
|
||||
|
||||
auto input1 = model->input(0);
|
||||
auto input2 = model->input("data1");
|
||||
|
||||
auto cloned_model = model->clone();
|
||||
|
||||
const auto fc = FunctionsComparator::with_default()
|
||||
.enable(FunctionsComparator::ATTRIBUTES)
|
||||
.enable(FunctionsComparator::CONST_VALUES);
|
||||
const auto res = fc.compare(model, cloned_model);
|
||||
EXPECT_TRUE(res.valid) << res.message;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue