Add support for ReduceL1 and ReduceL2 to ONNX Importer (#1838)
This commit is contained in:
parent
c147f03d5f
commit
d3682417bb
@ -39,7 +39,6 @@ namespace ngraph
|
||||
///
|
||||
/// \param arg The tensor to be reduced.
|
||||
/// \param reduction_axes The axis positions (0-based) to be eliminated.
|
||||
/// \param p The scalar defining the order of normalization.
|
||||
/// \param keep_dims If set to true it holds axes that are used for reduction.
|
||||
ReduceL1(const Output<Node>& arg,
|
||||
const Output<Node>& reduction_axes,
|
||||
|
@ -59,28 +59,24 @@ namespace ngraph
|
||||
|
||||
OutputVector reduce_l1(const Node& node)
|
||||
{
|
||||
auto l1_norm_reduction = [](const Output<ngraph::Node>& node,
|
||||
const ngraph::AxisSet& axis_set) {
|
||||
const auto axis_set_const = default_opset::Constant::create(
|
||||
element::i64, {axis_set.size()}, axis_set.to_vector());
|
||||
return ngraph::builder::opset1::l1_norm(node, axis_set_const, 0.f);
|
||||
};
|
||||
|
||||
return {reduction::make_ng_reduction_op(
|
||||
node, node.get_ng_inputs().at(0), l1_norm_reduction)};
|
||||
node,
|
||||
node.get_ng_inputs().at(0),
|
||||
std::make_shared<default_opset::ReduceL1,
|
||||
const Output<ngraph::Node>&,
|
||||
const Output<ngraph::Node>&,
|
||||
bool>)};
|
||||
}
|
||||
|
||||
OutputVector reduce_l2(const Node& node)
|
||||
{
|
||||
auto l2_norm_reduction = [](const Output<ngraph::Node>& node,
|
||||
const ngraph::AxisSet& axis_set) {
|
||||
const auto axis_set_const = default_opset::Constant::create(
|
||||
element::i64, {axis_set.size()}, axis_set.to_vector());
|
||||
return ngraph::builder::opset1::l2_norm(
|
||||
node, axis_set_const, 0.f, ngraph::builder::BiasMode::ADD, false);
|
||||
};
|
||||
return {reduction::make_ng_reduction_op(
|
||||
node, node.get_ng_inputs().at(0), l2_norm_reduction)};
|
||||
node,
|
||||
node.get_ng_inputs().at(0),
|
||||
std::make_shared<default_opset::ReduceL2,
|
||||
const Output<ngraph::Node>&,
|
||||
const Output<ngraph::Node>&,
|
||||
bool>)};
|
||||
}
|
||||
|
||||
OutputVector reduce_max(const Node& node)
|
||||
|
@ -96,7 +96,6 @@ def test_reduce_l1(reduction_axes):
|
||||
assert np.allclose(expected, ng_result)
|
||||
|
||||
|
||||
@xfail_issue_35925
|
||||
def test_reduce_l1_default_axes():
|
||||
shape = [2, 4, 3, 2]
|
||||
np.random.seed(133391)
|
||||
@ -108,7 +107,7 @@ def test_reduce_l1_default_axes():
|
||||
assert np.array_equal(expected.shape, ng_result.shape)
|
||||
assert np.allclose(expected, ng_result)
|
||||
|
||||
expected = np.sum(np.abs(input_data), keepdims=False)
|
||||
expected = np.array([np.sum(np.abs(input_data), keepdims=False)])
|
||||
node = onnx.helper.make_node("ReduceL1", inputs=["x"], outputs=["y"], keepdims=0)
|
||||
ng_result = np.array(run_node(node, [input_data]).pop())
|
||||
assert np.array_equal(expected.shape, ng_result.shape)
|
||||
@ -135,7 +134,6 @@ def test_reduce_l2(reduction_axes):
|
||||
assert np.allclose(expected, ng_result)
|
||||
|
||||
|
||||
@xfail_issue_35925
|
||||
def test_reduce_l2_default_axes():
|
||||
shape = [2, 4, 3, 2]
|
||||
np.random.seed(133391)
|
||||
@ -147,7 +145,7 @@ def test_reduce_l2_default_axes():
|
||||
assert np.array_equal(expected.shape, ng_result.shape)
|
||||
assert np.allclose(expected, ng_result)
|
||||
|
||||
expected = np.sqrt(np.sum(np.square(input_data), keepdims=False))
|
||||
expected = np.array([np.sqrt(np.sum(np.square(input_data), keepdims=False))])
|
||||
node = onnx.helper.make_node("ReduceL2", inputs=["x"], outputs=["y"], keepdims=0)
|
||||
ng_result = np.array(run_node(node, [input_data]).pop())
|
||||
assert np.array_equal(expected.shape, ng_result.shape)
|
||||
|
Loading…
Reference in New Issue
Block a user