Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
090f16ec
Commit
090f16ec
authored
Sep 04, 2019
by
mbencer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed problem with NormalizeL2
parent
4954b8d5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
61 deletions
+61
-61
normalize_l2.cpp
src/ngraph/op/fused/normalize_l2.cpp
+3
-13
fused_op.in.cpp
test/backend/fused_op.in.cpp
+58
-6
normalize.cpp
test/type_prop/normalize.cpp
+0
-42
No files found.
src/ngraph/op/fused/normalize_l2.cpp
View file @
090f16ec
...
...
@@ -48,16 +48,6 @@ void op::NormalizeL2::pre_validate_and_infer_types()
NODE_VALIDATION_CHECK
(
this
,
data_pshape
.
is_static
(),
"Input data must be static."
);
NODE_VALIDATION_CHECK
(
this
,
axes_pshape
.
is_static
(),
"Input axes must be static."
);
const
Shape
data_shape
{
data_pshape
.
to_shape
()};
// Input data must be 2, 3 or 4D tensor.
NODE_VALIDATION_CHECK
(
this
,
(
data_shape
.
size
()
>=
2
&&
data_shape
.
size
()
<=
4
),
"Input tensor rank must be 2, 3 or 4 dimensional (actual input "
"shape: "
,
data_shape
,
")."
);
NODE_VALIDATION_CHECK
(
this
,
static_cast
<
size_t
>
(
axes_pshape
.
rank
())
==
1
,
"Input axes must have rank equals 1 (axes shape: "
,
...
...
@@ -71,7 +61,7 @@ NodeVector op::NormalizeL2::decompose_op() const
const
Shape
input_shape
{
data
.
get_shape
()};
// Reshape to 4D tensor.
if
(
input_shape
.
size
()
!=
4
)
if
(
input_shape
.
size
()
<
4
)
{
Shape
data_shape
(
4
-
input_shape
.
size
(),
1
);
copy
(
begin
(
input_shape
),
end
(
input_shape
),
back_inserter
(
data_shape
));
...
...
@@ -92,12 +82,12 @@ NodeVector op::NormalizeL2::decompose_op() const
auto
builder_bias_mode
=
(
m_eps_mode
==
EpsMode
::
MAX
)
?
builder
::
BiasMode
::
MAX
:
builder
::
BiasMode
::
ADD
;
Output
<
Node
>
norm
=
builder
::
l2_norm
(
data
,
reduction_axes
,
m_eps
,
builder_bias_mode
);
norm
=
make_broadcast_node
(
norm
,
data
.
get_shape
(),
0
);
norm
=
numpy_style_broadcast
(
norm
,
data
.
get_shape
()
);
data
=
data
/
norm
;
// get back original input tensor rank
if
(
input_shape
.
size
()
!=
4
)
if
(
input_shape
.
size
()
<
4
)
{
data
=
builder
::
reshape
(
data
,
input_shape
);
}
...
...
test/backend/fused_op.in.cpp
View file @
090f16ec
...
...
@@ -691,11 +691,11 @@ NGRAPH_TEST(${BACKEND_NAME}, normalize_across_empty_axes_input)
test_case
.
run
(
DEFAULT_FLOAT_TOLERANCE_BITS
+
1
);
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
normalize_across_h
w
_4d
)
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
normalize_across_h_4d
)
{
Shape
data_shape
{
1
,
2
,
3
,
4
};
auto
data
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
data_shape
);
const
auto
axes
=
make_shared
<
op
::
Constant
>
(
element
::
u64
,
Shape
{
2
},
vector
<
int64_t
>
{
2
,
3
});
const
auto
axes
=
make_shared
<
op
::
Constant
>
(
element
::
u64
,
Shape
{
1
},
vector
<
int64_t
>
{
1
});
float
eps
{
1e-6
f
};
auto
eps_mode
=
op
::
EpsMode
::
ADD
;
...
...
@@ -710,10 +710,62 @@ NGRAPH_TEST(${BACKEND_NAME}, normalize_across_hw_4d)
test_case
.
add_input
<
float
>
(
input_data
);
test_case
.
add_expected_output
<
float
>
(
data_shape
,
{
0.03922323
f
,
0.07844646
f
,
0.11766968
f
,
0.15689291
f
,
0.19611613
f
,
0.23533936
f
,
0.2745626
f
,
0.31378582
f
,
0.35300905
f
,
0.39223227
f
,
0.43145549
f
,
0.47067872
f
,
0.1994109
f
,
0.2147502
f
,
0.2300895
f
,
0.2454288
f
,
0.26076809
f
,
0.2761074
f
,
0.29144669
f
,
0.306786
f
,
0.32212529
f
,
0.3374646
f
,
0.35280389
f
,
0.3681432
f
});
data_shape
,
{
0.0766965
f
,
0.14142136
f
,
0.19611613
f
,
0.24253564
f
,
0.28216633
f
,
0.31622776
f
,
0.34570536
f
,
0.37139067
f
,
0.39391932
f
,
0.41380295
f
,
0.43145549
f
,
0.44721359
f
,
0.99705452
f
,
0.98994946
f
,
0.98058069
f
,
0.97014254
f
,
0.95936549
f
,
0.94868332
f
,
0.93834311
f
,
0.92847669
f
,
0.91914505
f
,
0.91036648
f
,
0.90213418
f
,
0.89442718
f
});
test_case
.
run
(
DEFAULT_FLOAT_TOLERANCE_BITS
+
1
);
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
normalize_across_1axis_5d
)
{
Shape
data_shape
{
1
,
2
,
2
,
2
,
3
};
auto
data
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
data_shape
);
const
auto
axes
=
make_shared
<
op
::
Constant
>
(
element
::
u64
,
Shape
{
1
},
vector
<
int64_t
>
{
1
});
float
eps
{
1e-6
f
};
auto
eps_mode
=
op
::
EpsMode
::
ADD
;
auto
normalize
=
make_shared
<
op
::
NormalizeL2
>
(
data
,
axes
,
eps
,
eps_mode
);
auto
function
=
make_shared
<
Function
>
(
NodeVector
{
normalize
},
ParameterVector
{
data
});
auto
test_case
=
test
::
NgraphTestCase
(
function
,
"${BACKEND_NAME}"
);
vector
<
float
>
input_data
(
shape_size
(
data_shape
));
iota
(
begin
(
input_data
),
end
(
input_data
),
1
);
test_case
.
add_input
<
float
>
(
input_data
);
test_case
.
add_expected_output
<
float
>
(
data_shape
,
{
0.0766965
f
,
0.14142136
f
,
0.19611613
f
,
0.24253564
f
,
0.28216633
f
,
0.31622776
f
,
0.34570536
f
,
0.37139067
f
,
0.39391932
f
,
0.41380295
f
,
0.43145549
f
,
0.44721359
f
,
0.99705452
f
,
0.98994946
f
,
0.98058069
f
,
0.97014254
f
,
0.95936549
f
,
0.94868332
f
,
0.93834311
f
,
0.92847669
f
,
0.91914505
f
,
0.91036648
f
,
0.90213418
f
,
0.89442718
f
});
test_case
.
run
(
DEFAULT_FLOAT_TOLERANCE_BITS
+
1
);
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
normalize_across_123axes_5d
)
{
Shape
data_shape
{
1
,
2
,
2
,
2
,
3
};
auto
data
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
data_shape
);
const
auto
axes
=
make_shared
<
op
::
Constant
>
(
element
::
u64
,
Shape
{
3
},
vector
<
int64_t
>
{
1
,
2
,
3
});
float
eps
{
1e-6
f
};
auto
eps_mode
=
op
::
EpsMode
::
ADD
;
auto
normalize
=
make_shared
<
op
::
NormalizeL2
>
(
data
,
axes
,
eps
,
eps_mode
);
auto
function
=
make_shared
<
Function
>
(
NodeVector
{
normalize
},
ParameterVector
{
data
});
auto
test_case
=
test
::
NgraphTestCase
(
function
,
"${BACKEND_NAME}"
);
vector
<
float
>
input_data
(
shape_size
(
data_shape
));
iota
(
begin
(
input_data
),
end
(
input_data
),
1
);
test_case
.
add_input
<
float
>
(
input_data
);
test_case
.
add_expected_output
<
float
>
(
data_shape
,
{
0.02638899
f
,
0.04956816
f
,
0.070014
f
,
0.10555596
f
,
0.1239204
f
,
0.140028
f
,
0.18472293
f
,
0.19827265
f
,
0.210042
f
,
0.26388991
f
,
0.27262488
f
,
0.280056
f
,
0.34305686
f
,
0.34697714
f
,
0.35007
f
,
0.42222384
f
,
0.42132938
f
,
0.420084
f
,
0.50139081
f
,
0.49568161
f
,
0.49009803
f
,
0.58055776
f
,
0.57003385
f
,
0.560112
f
});
test_case
.
run
(
DEFAULT_FLOAT_TOLERANCE_BITS
+
1
);
}
...
...
test/type_prop/normalize.cpp
View file @
090f16ec
...
...
@@ -20,48 +20,6 @@
using
namespace
std
;
using
namespace
ngraph
;
TEST
(
type_prop
,
normalize_invalid_input_tensor_rank
)
{
Shape
data_shape
{
1
,
2
,
3
,
4
,
5
};
auto
data
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
data_shape
);
auto
axes
=
make_shared
<
op
::
Parameter
>
(
element
::
u64
,
Shape
{
1
,
2
});
float
eps
{
1e-6
f
};
auto
eps_mode
=
op
::
EpsMode
::
ADD
;
try
{
auto
normalize
=
make_shared
<
op
::
NormalizeL2
>
(
data
,
axes
,
eps
,
eps_mode
);
// Should have thrown, so fail if it didn't
FAIL
()
<<
"Invalid input tensor rank."
;
}
catch
(
const
NodeValidationFailure
&
error
)
{
EXPECT_HAS_SUBSTRING
(
error
.
what
(),
std
::
string
(
"Input tensor rank must be 2, 3 or 4 dimensional"
));
}
catch
(...)
{
FAIL
()
<<
"Deduced type check failed for unexpected reason"
;
}
data
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
2
});
try
{
auto
normalize
=
make_shared
<
op
::
NormalizeL2
>
(
data
,
axes
,
eps
,
eps_mode
);
// Should have thrown, so fail if it didn't
FAIL
()
<<
"Invalid input tensor rank."
;
}
catch
(
const
NodeValidationFailure
&
error
)
{
EXPECT_HAS_SUBSTRING
(
error
.
what
(),
std
::
string
(
"Input tensor rank must be 2, 3 or 4 dimensional"
));
}
catch
(...)
{
FAIL
()
<<
"Deduced type check failed for unexpected reason"
;
}
}
TEST
(
type_prop
,
normalize_invalid_axes_rank
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment