Skip to content

Commit

Permalink
Avoid replace parameter in reshape method (openvinotoolkit#6741)
Browse files Browse the repository at this point in the history
* Avoid replace parameter in reshape method

* Added comment

* Use set_partial_shape()
  • Loading branch information
ilyachur authored and akuporos committed Sep 29, 2021
1 parent 6c51588 commit 0539a8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,10 @@ CNNNetworkNGraphImpl::reshape(const std::map<std::string, ngraph::PartialShape>&

bool parameter_replaced = false;
for (size_t i = 0; i < params.size(); i++) {
const auto& param = params[i];
auto& param = params[i];
if (inputShapes.find(param->get_friendly_name()) == inputShapes.end())
continue;
::ngraph::PartialShape shape(inputShapes.at(param->get_friendly_name()));
auto newParam = std::make_shared<::ngraph::op::Parameter>(param->get_element_type(), shape);
newParam->set_friendly_name(param->get_friendly_name());
_ngraph_function->replace_parameter(i, newParam);
param->set_partial_shape(inputShapes.at(param->get_friendly_name()));
parameter_replaced = true;
}
if (parameter_replaced)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@ TEST_F(NGraphReshapeTests, ReshapeSpatialReLU) {
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ngraph::Shape({1, 3, 25, 25}));
}

TEST_F(NGraphReshapeTests, ReshapeSpatialReLUWithoutReplaceParameter) {
std::shared_ptr<ngraph::Function> ngraph;
{
ngraph::PartialShape shape({1, 3, 22, 22});
ngraph::element::Type type(ngraph::element::Type_t::f32);
auto param = std::make_shared<ngraph::op::Parameter>(type, shape);
auto relu = std::make_shared<ngraph::op::Relu>(param);
auto result = std::make_shared<ngraph::op::Result>(relu);

ngraph::ParameterVector params = {param};
ngraph::ResultVector results = {result};

ngraph = std::make_shared<ngraph::Function>(results, params);
}

ASSERT_EQ(ngraph->get_parameters()[0]->get_shape(), ngraph::Shape({1, 3, 22, 22}));
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ngraph::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->get_parameters()[0]->get_shape(), ngraph::Shape({1, 3, 25, 25}));
ASSERT_EQ(ngraph->get_results()[0]->get_shape(), ngraph::Shape({1, 3, 25, 25}));
}


TEST_F(NGraphReshapeTests, CNNReshapeSpatialReLU) {
std::shared_ptr<const ngraph::Function> ngraph;
{
Expand Down

0 comments on commit 0539a8f

Please sign in to comment.