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
<< " alpha value should be in range (0,1)";
std::shared_ptr<ngraph::Node> alpha_node =
std::make_shared<default_opset::Constant>(data->get_element_type(),
data->get_shape(),
std::vector<double>{alpha});
default_opset::Constant::create(data->get_element_type(), Shape{}, {alpha});
return {std::make_shared<default_opset::PRelu>(data, alpha_node)};
}
......
......@@ -29,14 +29,8 @@ namespace ngraph
NodeVector mean(const Node& node)
{
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(
sum->get_element_type(),
shape,
std::vector<int>(shape_size(shape), node.get_ng_inputs().size()));
sum->get_element_type(), Shape{}, {node.get_ng_inputs().size()});
return {std::make_shared<default_opset::Divide>(sum, count)};
}
......
......@@ -32,8 +32,8 @@ namespace ngraph
{
auto data = node.get_ng_inputs().at(0);
auto one_node = default_opset::Constant::create(
data->get_element_type(), data->get_shape(), {1});
auto one_node =
default_opset::Constant::create(data->get_element_type(), Shape{}, {1});
return {std::make_shared<default_opset::Divide>(one_node, data)};
}
......
......@@ -38,11 +38,11 @@ namespace ngraph
auto gamma =
node.get_attribute_value<double>("gamma", 1.05070102214813232421875);
auto alpha_node = std::make_shared<default_opset::Constant>(
data->get_element_type(), data->get_shape(), std::vector<double>{alpha});
auto alpha_node =
default_opset::Constant::create(data->get_element_type(), Shape{}, {alpha});
auto gamma_node = std::make_shared<default_opset::Constant>(
data->get_element_type(), data->get_shape(), std::vector<double>{gamma});
auto gamma_node =
default_opset::Constant::create(data->get_element_type(), Shape{}, {gamma});
return {std::make_shared<default_opset::Selu>(data, alpha_node, gamma_node)};
}
......
......@@ -41,22 +41,22 @@ namespace ngraph
const auto input_element_type = input->get_element_type();
if (input_element_type.is_signed())
{
negative_lambd = default_opset::Constant::create(
input_element_type, input->get_shape(), {-lambd});
negative_lambd =
default_opset::Constant::create(input_element_type, Shape{}, {-lambd});
}
else
{
// Passing -lambd to unsigned type constant will cause an overflow.
// For unsigned types the lowest possible value is 0.
negative_lambd = default_opset::Constant::create(
input_element_type, input->get_shape(), {0});
negative_lambd =
default_opset::Constant::create(input_element_type, Shape{}, {0});
}
const auto positive_lambd = default_opset::Constant::create(
input_element_type, input->get_shape(), {lambd});
const auto positive_lambd =
default_opset::Constant::create(input_element_type, Shape{}, {lambd});
const auto bias_tensor = default_opset::Constant::create(
input_element_type, input->get_shape(), {bias});
const auto bias_tensor =
default_opset::Constant::create(input_element_type, Shape{}, {bias});
// Create a mask indicating locations of values that need to be adjusted
// by adding and subtracting bias
......
......@@ -33,11 +33,9 @@ namespace ngraph
const auto data = node.get_ng_inputs().at(0);
const std::shared_ptr<ngraph::Node> zero_node =
std::make_shared<default_opset::Constant>(
data->get_element_type(), data->get_shape(), std::vector<float>{0.f});
default_opset::Constant::create(data->get_element_type(), Shape{}, {0.f});
const std::shared_ptr<ngraph::Node> one_node =
std::make_shared<default_opset::Constant>(
data->get_element_type(), data->get_shape(), std::vector<float>{1.f});
default_opset::Constant::create(data->get_element_type(), Shape{}, {1.f});
// data + log(exp(-data) + 1)
const std::shared_ptr<ngraph::Node> positive_val_node =
......
......@@ -18,10 +18,6 @@
#include <vector>
#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 "softsign.hpp"
......@@ -38,11 +34,12 @@ namespace ngraph
auto data = node.get_ng_inputs().at(0);
std::shared_ptr<ngraph::Node> one_node =
std::make_shared<default_opset::Constant>(
data->get_element_type(), Shape{}, std::vector<double>{1});
one_node = ngraph::builder::make_broadcast_node(one_node, data->get_shape());
default_opset::Constant::create(data->get_element_type(), Shape{}, {1});
auto abs_data = std::make_shared<default_opset::Abs>(data);
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
......
......@@ -33,8 +33,8 @@ namespace ngraph
const auto data = node.get_ng_inputs().at(0);
const double alpha = node.get_attribute_value<double>("alpha", 1.0);
const auto alpha_node = default_opset::Constant::create(
data->get_element_type(), data->get_shape(), {alpha});
const auto alpha_node =
default_opset::Constant::create(data->get_element_type(), Shape{}, {alpha});
const auto data_map = std::make_shared<default_opset::Convert>(
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