Dynamism in new API (#7742)
* Fixed precisions conversion in new API * Added tests * Fixed old IR cases * Disable FP16 * Fixed regex for CentoOS * Refactored tests to use new API * Temp * Fixed tests * Moved smart reshape related sources to ngraph * Added tests for invalid names * Moved reshape to tensor_names * clang-format * Fixed CC build * Removed IEConv, IEDeconv from primitives pririty
This commit is contained in:
1 parent
bd5b1bf99f
commit
757db35528
35 files changed
+958
-716
No files matched your search
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/core/partial_shape.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
TEST(function, get_input_by_tensor_name) {
|
||||
@@ -511,3 +512,243 @@ TEST(function, DISABLED_create_function_with_incorrect_tensor_names_from_const_f
|
||||
auto f = std::make_shared<const ov::Function>(relu, ov::ParameterVector{arg0});
|
||||
ASSERT_THROW(f->validate_nodes_and_infer_types(), ov::Exception);
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapedDynamicShapeLayout) {
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({-1, 3, 22, 22});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->get_output_tensor(0).set_names({"tensor"});
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ngraph = std::make_shared<ov::Function>(relu, params);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(ngraph->input().get_partial_shape().is_dynamic());
|
||||
|
||||
std::map<std::string, ov::PartialShape> new_shape;
|
||||
new_shape["tensor"] = ov::Shape{1, 3, 22, 22};
|
||||
ASSERT_NO_THROW(ngraph->reshape(new_shape));
|
||||
|
||||
EXPECT_FALSE(ngraph->input().get_partial_shape().is_dynamic());
|
||||
EXPECT_FALSE(ngraph->get_parameters().front()->get_partial_shape().is_dynamic());
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapeBatchReLU) {
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({1, 3, 22, 22});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->get_output_tensor(0).set_names({"tensor"});
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(relu);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ov::ResultVector results = {result};
|
||||
|
||||
ngraph = std::make_shared<ov::Function>(results, params);
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
|
||||
{
|
||||
std::map<std::string, ov::PartialShape> new_shape;
|
||||
new_shape["tensor"] = ov::PartialShape{2, 3, 22, 22};
|
||||
ASSERT_NO_THROW(ngraph->reshape(new_shape));
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({2, 3, 22, 22}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({2, 3, 22, 22}));
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapeSpatialReLU) {
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({1, 3, 22, 22});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->get_output_tensor(0).set_names({"tensor"});
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(relu);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ov::ResultVector results = {result};
|
||||
|
||||
ngraph = std::make_shared<ov::Function>(results, params);
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
|
||||
{
|
||||
std::map<std::string, ov::PartialShape> new_shape;
|
||||
new_shape["tensor"] = ov::PartialShape{1, 3, 25, 25};
|
||||
ASSERT_NO_THROW(ngraph->reshape(new_shape));
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({1, 3, 25, 25}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({1, 3, 25, 25}));
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapeSpatialReLUWithoutReplaceParameter) {
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({1, 3, 22, 22});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(relu);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ov::ResultVector results = {result};
|
||||
|
||||
ngraph = std::make_shared<ov::Function>(results, params);
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
|
||||
{
|
||||
ngraph->get_parameters()[0]->set_partial_shape({1, 3, 25, 25});
|
||||
ngraph->validate_nodes_and_infer_types();
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->input().get_partial_shape(), ov::Shape({1, 3, 25, 25}));
|
||||
ASSERT_EQ(ngraph->output().get_partial_shape(), ov::Shape({1, 3, 25, 25}));
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapeSpatialReLUStaticToDynamic) {
|
||||
const ov::PartialShape refShape{1, 3, ov::Dimension::dynamic(), 25};
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({1, 3, 22, 22});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->get_output_tensor(0).set_names({"tensor"});
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(relu);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ov::ResultVector results = {result};
|
||||
|
||||
ngraph = std::make_shared<ov::Function>(results, params);
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
|
||||
{
|
||||
std::map<std::string, ov::PartialShape> new_shape;
|
||||
new_shape["tensor"] = refShape;
|
||||
ASSERT_NO_THROW(ngraph->reshape(new_shape));
|
||||
}
|
||||
|
||||
ASSERT_TRUE(ngraph->input(0).get_partial_shape().is_dynamic());
|
||||
ASSERT_TRUE(ngraph->output(0).get_partial_shape().is_dynamic());
|
||||
ASSERT_EQ(ngraph->input(0).get_partial_shape(), refShape);
|
||||
ASSERT_EQ(ngraph->output(0).get_partial_shape(), refShape);
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapeSpatialReLUStaticToFullyDynamic) {
|
||||
const ov::PartialShape refShape = ov::PartialShape::dynamic();
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({1, 3, 22, 22});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->get_output_tensor(0).set_names({"tensor"});
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(relu);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ov::ResultVector results = {result};
|
||||
|
||||
ngraph = std::make_shared<ov::Function>(results, params);
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ov::Shape({1, 3, 22, 22}));
|
||||
|
||||
{
|
||||
std::map<std::string, ov::PartialShape> new_shape;
|
||||
new_shape["tensor"] = refShape;
|
||||
ASSERT_NO_THROW(ngraph->reshape(new_shape));
|
||||
}
|
||||
|
||||
ASSERT_TRUE(ngraph->input().get_partial_shape().is_dynamic());
|
||||
ASSERT_TRUE(ngraph->output().get_partial_shape().is_dynamic());
|
||||
ASSERT_EQ(ngraph->input().get_partial_shape(), refShape);
|
||||
ASSERT_EQ(ngraph->output().get_partial_shape(), refShape);
|
||||
}
|
||||
|
||||
TEST(function_reshape, ReshapeSpatialReLUDynamicToDynamic) {
|
||||
const ov::PartialShape refShape{1, 3, ov::Dimension::dynamic(), 25};
|
||||
std::shared_ptr<ov::Function> ngraph;
|
||||
{
|
||||
ov::PartialShape shape({1, 3, 22, ov::Dimension::dynamic()});
|
||||
ov::element::Type type(ov::element::Type_t::f32);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->get_output_tensor(0).set_names({"tensor"});
|
||||
auto relu = std::make_shared<ov::op::v0::Relu>(param);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(relu);
|
||||
|
||||
ov::ParameterVector params = {param};
|
||||
ov::ResultVector results = {result};
|
||||
|
||||
ngraph = std::make_shared<ov::Function>(results, params);
|
||||
}
|
||||
|
||||
ASSERT_EQ(ngraph->input().get_partial_shape(), ov::PartialShape({1, 3, 22, ov::Dimension::dynamic()}));
|
||||
ASSERT_EQ(ngraph->output().get_partial_shape(), ov::PartialShape({1, 3, 22, ov::Dimension::dynamic()}));
|
||||
|
||||
{
|
||||
std::map<std::string, ov::PartialShape> new_shape;
|
||||
new_shape["tensor"] = refShape;
|
||||
ASSERT_NO_THROW(ngraph->reshape(new_shape));
|
||||
}
|
||||
|
||||
ASSERT_TRUE(ngraph->input().get_partial_shape().is_dynamic());
|
||||
ASSERT_TRUE(ngraph->output().get_partial_shape().is_dynamic());
|
||||
ASSERT_EQ(ngraph->input().get_partial_shape(), refShape);
|
||||
ASSERT_EQ(ngraph->output().get_partial_shape(), refShape);
|
||||
}
|
||||
|
||||
TEST(function_reshape, TestInvalidReshape) {
|
||||
std::shared_ptr<ov::Function> f;
|
||||
{
|
||||
auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1000, 4});
|
||||
input->get_output_tensor(0).set_names({"tensor"});
|
||||
auto shape = ov::op::v0::Constant::create(ov::element::i64, {2}, {1, 4000});
|
||||
auto reshape = std::make_shared<ov::op::v1::Reshape>(input, shape, true);
|
||||
f = std::make_shared<ov::Function>(ov::OutputVector{reshape}, ov::ParameterVector{input});
|
||||
}
|
||||
|
||||
ASSERT_ANY_THROW(f->reshape({{"tensor", ov::Shape({4})}}));
|
||||
|
||||
auto param = f->get_parameters().front();
|
||||
ASSERT_EQ(param->get_output_shape(0), ov::Shape({1, 1000, 4}));
|
||||
|
||||
ASSERT_NO_THROW(f->reshape({{"tensor", ov::Shape({1, 1000, 4})}}));
|
||||
}
|
||||
|
||||
TEST(function_reshape, TestReshapeWithInvalidTensorName) {
|
||||
std::shared_ptr<ov::Function> f;
|
||||
{
|
||||
auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1000, 4});
|
||||
input->set_friendly_name("param");
|
||||
input->get_output_tensor(0).set_names({"tensor"});
|
||||
auto shape = ov::op::v0::Constant::create(ov::element::i64, {2}, {1, 4000});
|
||||
auto reshape = std::make_shared<ov::op::v1::Reshape>(input, shape, true);
|
||||
f = std::make_shared<ov::Function>(ov::OutputVector{reshape}, ov::ParameterVector{input});
|
||||
}
|
||||
|
||||
// both operation names and tensor names are specified
|
||||
ASSERT_ANY_THROW(f->reshape({{"param", ov::Shape({4, 4, 4})}, {"tensor", ov::Shape({4, 4, 4})}}));
|
||||
|
||||
// operation name does not work
|
||||
ASSERT_ANY_THROW(f->reshape({{"param", ov::Shape({4, 4, 4})}}));
|
||||
}
|
||||
Reference in new issue
Block a user