Unverified Commit 87eae9b0 authored by Ewa Tusień's avatar Ewa Tusień Committed by GitHub

[ONNX] Change constants' target shape to scalar shape (#4345)

* Changed constant to scalar.

* Used v1 div.

* Code refactoring.

* Bugfix.

* Bugfix

* Bugfix

* Code formatting.
Co-authored-by: 's avatarScott Cyphers <diyessi@users.noreply.github.com>
parent e6b26ac6
...@@ -37,9 +37,7 @@ namespace ngraph ...@@ -37,9 +37,7 @@ namespace ngraph
<< " alpha value should be in range (0,1)"; << " alpha value should be in range (0,1)";
std::shared_ptr<ngraph::Node> alpha_node = std::shared_ptr<ngraph::Node> alpha_node =
std::make_shared<default_opset::Constant>(data->get_element_type(), default_opset::Constant::create(data->get_element_type(), Shape{}, {alpha});
data->get_shape(),
std::vector<double>{alpha});
return {std::make_shared<default_opset::PRelu>(data, alpha_node)}; return {std::make_shared<default_opset::PRelu>(data, alpha_node)};
} }
......
...@@ -29,14 +29,8 @@ namespace ngraph ...@@ -29,14 +29,8 @@ namespace ngraph
NodeVector mean(const Node& node) NodeVector mean(const Node& node)
{ {
auto sum = variadic::make_ng_variadic_op<default_opset::Add>(node).front(); auto sum = variadic::make_ng_variadic_op<default_opset::Add>(node).front();
auto shape = sum->get_shape();
// Create a Constant representing the number of inputs with the same shape as
// sum
auto count = default_opset::Constant::create( auto count = default_opset::Constant::create(
sum->get_element_type(), sum->get_element_type(), Shape{}, {node.get_ng_inputs().size()});
shape,
std::vector<int>(shape_size(shape), node.get_ng_inputs().size()));
return {std::make_shared<default_opset::Divide>(sum, count)}; return {std::make_shared<default_opset::Divide>(sum, count)};
} }
......
...@@ -32,8 +32,8 @@ namespace ngraph ...@@ -32,8 +32,8 @@ namespace ngraph
{ {
auto data = node.get_ng_inputs().at(0); auto data = node.get_ng_inputs().at(0);
auto one_node = default_opset::Constant::create( auto one_node =
data->get_element_type(), data->get_shape(), {1}); default_opset::Constant::create(data->get_element_type(), Shape{}, {1});
return {std::make_shared<default_opset::Divide>(one_node, data)}; return {std::make_shared<default_opset::Divide>(one_node, data)};
} }
......
...@@ -38,11 +38,11 @@ namespace ngraph ...@@ -38,11 +38,11 @@ namespace ngraph
auto gamma = auto gamma =
node.get_attribute_value<double>("gamma", 1.05070102214813232421875); node.get_attribute_value<double>("gamma", 1.05070102214813232421875);
auto alpha_node = std::make_shared<default_opset::Constant>( auto alpha_node =
data->get_element_type(), data->get_shape(), std::vector<double>{alpha}); default_opset::Constant::create(data->get_element_type(), Shape{}, {alpha});
auto gamma_node = std::make_shared<default_opset::Constant>( auto gamma_node =
data->get_element_type(), data->get_shape(), std::vector<double>{gamma}); default_opset::Constant::create(data->get_element_type(), Shape{}, {gamma});
return {std::make_shared<default_opset::Selu>(data, alpha_node, gamma_node)}; return {std::make_shared<default_opset::Selu>(data, alpha_node, gamma_node)};
} }
......
...@@ -41,22 +41,22 @@ namespace ngraph ...@@ -41,22 +41,22 @@ namespace ngraph
const auto input_element_type = input->get_element_type(); const auto input_element_type = input->get_element_type();
if (input_element_type.is_signed()) if (input_element_type.is_signed())
{ {
negative_lambd = default_opset::Constant::create( negative_lambd =
input_element_type, input->get_shape(), {-lambd}); default_opset::Constant::create(input_element_type, Shape{}, {-lambd});
} }
else else
{ {
// Passing -lambd to unsigned type constant will cause an overflow. // Passing -lambd to unsigned type constant will cause an overflow.
// For unsigned types the lowest possible value is 0. // For unsigned types the lowest possible value is 0.
negative_lambd = default_opset::Constant::create( negative_lambd =
input_element_type, input->get_shape(), {0}); default_opset::Constant::create(input_element_type, Shape{}, {0});
} }
const auto positive_lambd = default_opset::Constant::create( const auto positive_lambd =
input_element_type, input->get_shape(), {lambd}); default_opset::Constant::create(input_element_type, Shape{}, {lambd});
const auto bias_tensor = default_opset::Constant::create( const auto bias_tensor =
input_element_type, input->get_shape(), {bias}); default_opset::Constant::create(input_element_type, Shape{}, {bias});
// Create a mask indicating locations of values that need to be adjusted // Create a mask indicating locations of values that need to be adjusted
// by adding and subtracting bias // by adding and subtracting bias
......
...@@ -33,11 +33,9 @@ namespace ngraph ...@@ -33,11 +33,9 @@ namespace ngraph
const auto data = node.get_ng_inputs().at(0); const auto data = node.get_ng_inputs().at(0);
const std::shared_ptr<ngraph::Node> zero_node = const std::shared_ptr<ngraph::Node> zero_node =
std::make_shared<default_opset::Constant>( default_opset::Constant::create(data->get_element_type(), Shape{}, {0.f});
data->get_element_type(), data->get_shape(), std::vector<float>{0.f});
const std::shared_ptr<ngraph::Node> one_node = const std::shared_ptr<ngraph::Node> one_node =
std::make_shared<default_opset::Constant>( default_opset::Constant::create(data->get_element_type(), Shape{}, {1.f});
data->get_element_type(), data->get_shape(), std::vector<float>{1.f});
// data + log(exp(-data) + 1) // data + log(exp(-data) + 1)
const std::shared_ptr<ngraph::Node> positive_val_node = const std::shared_ptr<ngraph::Node> positive_val_node =
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
#include <vector> #include <vector>
#include "default_opset.hpp" #include "default_opset.hpp"
#include "ngraph/builder/autobroadcast.hpp"
#include "ngraph/op/abs.hpp"
#include "ngraph/op/add.hpp"
#include "ngraph/op/divide.hpp"
#include "ngraph/shape.hpp" #include "ngraph/shape.hpp"
#include "softsign.hpp" #include "softsign.hpp"
...@@ -38,11 +34,12 @@ namespace ngraph ...@@ -38,11 +34,12 @@ namespace ngraph
auto data = node.get_ng_inputs().at(0); auto data = node.get_ng_inputs().at(0);
std::shared_ptr<ngraph::Node> one_node = std::shared_ptr<ngraph::Node> one_node =
std::make_shared<default_opset::Constant>( default_opset::Constant::create(data->get_element_type(), Shape{}, {1});
data->get_element_type(), Shape{}, std::vector<double>{1}); auto abs_data = std::make_shared<default_opset::Abs>(data);
one_node = ngraph::builder::make_broadcast_node(one_node, data->get_shape()); auto data_plus_one_node =
std::make_shared<default_opset::Add>(abs_data, one_node);
return {data / (std::make_shared<default_opset::Abs>(data) + one_node)}; return {std::make_shared<default_opset::Divide>(data, data_plus_one_node)};
} }
} // namespace set_1 } // namespace set_1
......
...@@ -33,8 +33,8 @@ namespace ngraph ...@@ -33,8 +33,8 @@ namespace ngraph
const auto data = node.get_ng_inputs().at(0); const auto data = node.get_ng_inputs().at(0);
const double alpha = node.get_attribute_value<double>("alpha", 1.0); const double alpha = node.get_attribute_value<double>("alpha", 1.0);
const auto alpha_node = default_opset::Constant::create( const auto alpha_node =
data->get_element_type(), data->get_shape(), {alpha}); default_opset::Constant::create(data->get_element_type(), Shape{}, {alpha});
const auto data_map = std::make_shared<default_opset::Convert>( const auto data_map = std::make_shared<default_opset::Convert>(
std::make_shared<default_opset::Greater>(data, alpha_node), std::make_shared<default_opset::Greater>(data, alpha_node),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment