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
189cf3b7
Unverified
Commit
189cf3b7
authored
6 years ago
by
Michał Karzyński
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ONNX] Refactor exceptions to asserts (#1573)
parent
37174c90
master
v0.29.0-rc.0
v0.28.0-rc.1
v0.28.0-rc.0
v0.27.1-rc.3
v0.27.1-rc.2
v0.27.1-rc.1
v0.27.1-rc.0
v0.27.0-rc.1
v0.27.0-rc.0
v0.26.1-rc.0
v0.26.0
v0.26.0-rc.8
v0.26.0-rc.7
v0.26.0-rc.6
v0.26.0-rc.5
v0.26.0-rc.4
v0.26.0-rc.3
v0.26.0-rc.2
v0.26.0-rc.0
v0.25.1-rc.11
v0.25.1-rc.10
v0.25.1-rc.9
v0.25.1-rc.8
v0.25.1-rc.7
v0.25.1-rc.6
v0.25.1-rc.5
v0.25.1-rc.4
v0.25.1-rc.3
v0.25.1-rc.2
v0.25.1-rc.1
v0.25.1-rc.0
v0.25.0
v0.25.0-rc.3
v0.25.0-rc.2
v0.25.0-rc.1
v0.25.0-rc.0
v0.25.0-dev.0
v0.24.0
v0.24.0-rc.3
v0.24.0-rc.2
v0.24.0-rc.1
v0.24.0-rc.0
v0.23.0-rc.7
v0.23.0-rc.6
v0.23.0-rc.5
v0.23.0-rc.4
v0.23.0-rc.3
v0.23.0-rc.2
v0.23.0-rc.1
v0.23.0-rc.0
v0.22.2-rc.0
v0.22.1
v0.22.1-rc.0
v0.22.0
v0.22.0-rc.2
v0.22.0-rc.0
v0.21.0
v0.21.0-rc.1
v0.21.0-rc.0
v0.20.1-rc.4
v0.20.1-rc.3
v0.20.1-rc.2
v0.20.1-rc.1
v0.20.1-rc.0
v0.20.0-rc.2
v0.20.0-rc.1
v0.20.0-rc.0
v0.20.0-dev.0
v0.19.1
v0.19.1-rc.0
v0.19.0
v0.19.0-rc.5
v0.19.0-rc.4
v0.19.0-rc.3
v0.19.0-rc.2
v0.19.0-rc.1
v0.19.0-rc.0
v0.18.1
v0.18.1-rc.1
v0.18.1-rc.0
v0.18.0
v0.18.0-rc.2
v0.18.0-rc.1
v0.18.0-rc.0
v0.17.0-rc.1
v0.17.0-rc.0
v0.16.0-rc.3
v0.16.0-rc.2
v0.16.0-rc.1
v0.16.0-rc.0
v0.15.1-rc.2
v0.15.1-rc.1
v0.15.0
v0.15.0-rc.2
v0.15.0-rc.1
v0.15.0-rc.0
v0.14.0
v0.14.0-rc.1
v0.14.0-rc.0
v0.13.0
v0.12.0
v0.12.0-rc.2
v0.12.0-rc.1
v0.12.0-rc.0
v0.11.1
v0.11.0
v0.11.0-rc.1
v0.11.0-rc.0
v0.10.1
v0.10.0
v0.10.0-rc.6
v0.10.0-rc.5
v0.10.0-rc.4
v0.10.0-rc.3
v0.10.0-rc.2
v0.10.0-rc.1
v0.10.0-rc.0
v0.9.1
v0.9.1-rc.0
v0.9.0
v0.9.0-rc.5
v0.9.0-rc.4
v0.9.0-rc.3
v0.9.0-rc.2
v0.9.0-rc.1
v0.9.0-rc.0
v0.8.2-rc.0
v0.8.1
v0.8.1-rc.0
v0.8.0
v0.8.0-rc.2
v0.8.0-rc.1
v0.8.0-rc.0
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
71 additions
and
97 deletions
+71
-97
assertion.hpp
src/ngraph/assertion.hpp
+2
-2
node.cpp
src/ngraph/frontend/onnx_import/core/node.cpp
+16
-0
node.hpp
src/ngraph/frontend/onnx_import/core/node.hpp
+6
-1
exceptions.hpp
src/ngraph/frontend/onnx_import/exceptions.hpp
+12
-13
batch_norm.cpp
src/ngraph/frontend/onnx_import/op/batch_norm.cpp
+2
-12
conv.cpp
src/ngraph/frontend/onnx_import/op/conv.cpp
+4
-9
flatten.cpp
src/ngraph/frontend/onnx_import/op/flatten.cpp
+2
-6
reshape.cpp
src/ngraph/frontend/onnx_import/op/reshape.cpp
+3
-10
softmax.cpp
src/ngraph/frontend/onnx_import/op/softmax.cpp
+5
-7
unsqueeze.cpp
src/ngraph/frontend/onnx_import/op/unsqueeze.cpp
+6
-10
reduction.hpp
src/ngraph/frontend/onnx_import/utils/reduction.hpp
+5
-9
reshape.cpp
src/ngraph/frontend/onnx_import/utils/reshape.cpp
+8
-18
No files found.
src/ngraph/assertion.hpp
View file @
189cf3b7
...
...
@@ -166,11 +166,11 @@ namespace ngraph
/// Asserts condition "cond" with an exception class of "T", at location "loc".
#define NGRAPH_ASSERT_STREAM_WITH_LOC(T, cond, loc) \
(
cond ? ::ngraph::DummyAssertionHelper().get_stream()
\
(
(cond) ? ::ngraph::DummyAssertionHelper().get_stream()
\
: ::ngraph::AssertionHelper<T>(__FILE__, __LINE__, #cond, loc).get_stream())
/// Asserts condition "cond" with an exception class of "T", and no location specified.
#define NGRAPH_ASSERT_STREAM(T, cond) \
(
cond ? ::ngraph::DummyAssertionHelper().get_stream()
\
(
(cond) ? ::ngraph::DummyAssertionHelper().get_stream()
\
: ::ngraph::AssertionHelper<T>(__FILE__, __LINE__, #cond).get_stream())
/// Fails unconditionally with an exception class of "T", at location "loc".
#define NGRAPH_FAIL_STREAM_WITH_LOC(T, loc) \
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/core/node.cpp
View file @
189cf3b7
...
...
@@ -33,6 +33,22 @@ namespace ngraph
return
result
;
}
std
::
string
Node
::
get_description
()
const
{
if
(
!
get_name
().
empty
())
{
return
get_name
();
}
std
::
stringstream
stream
;
for
(
std
::
size_t
index
=
0
;
index
<
m_output_names
.
size
();
++
index
)
{
stream
<<
(
index
!=
0
?
", "
:
""
);
stream
<<
m_output_names
.
at
(
index
).
get
();
}
return
stream
.
str
();
}
}
// namespace onnx_import
}
// namespace ngraph
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/core/node.hpp
View file @
189cf3b7
...
...
@@ -72,6 +72,11 @@ namespace ngraph
const
std
::
string
&
op_type
()
const
{
return
m_node_proto
->
op_type
();
}
const
std
::
string
&
get_name
()
const
{
return
m_node_proto
->
name
();
}
/// @brief Describe the ONNX Node to make debugging graphs easier
/// Function will return the Node's name if it has one, or the names of its outputs.
/// \return Description of Node
std
::
string
get_description
()
const
;
const
std
::
vector
<
std
::
reference_wrapper
<
const
std
::
string
>>&
get_output_names
()
const
{
return
m_output_names
;
...
...
@@ -114,7 +119,7 @@ namespace ngraph
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
outs
,
const
Node
&
node
)
{
return
(
outs
<<
"<Node("
<<
node
.
op_type
()
<<
"): "
<<
node
.
get_
name
()
<<
">"
);
return
(
outs
<<
"<Node("
<<
node
.
op_type
()
<<
"): "
<<
node
.
get_
description
()
<<
">"
);
}
}
// namespace onnx_import
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/exceptions.hpp
View file @
189cf3b7
...
...
@@ -16,6 +16,7 @@
#pragma once
#include "ngraph/assertion.hpp"
#include "ngraph/except.hpp"
namespace
ngraph
...
...
@@ -24,31 +25,29 @@ namespace ngraph
{
namespace
error
{
struct
NotSupported
:
ngraph_error
struct
NotSupported
:
AssertionFailure
{
explicit
NotSupported
(
const
std
::
string
&
op_name
,
const
std
::
string
&
name
,
const
std
::
string
&
message
)
:
ngraph_error
{
op_name
+
" node ("
+
name
+
"): "
+
message
}
explicit
NotSupported
(
const
std
::
string
&
what_arg
)
:
AssertionFailure
(
what_arg
)
{
}
};
namespace
parameter
struct
InvalidArgument
:
AssertionFailure
{
struct
Value
:
ngraph_error
{
Value
(
const
std
::
string
&
op_name
,
const
std
::
string
&
name
,
const
std
::
string
&
message
)
:
ngraph_error
{
op_name
+
" node ("
+
name
+
"): "
+
message
}
explicit
InvalidArgument
(
const
std
::
string
&
what_arg
)
:
AssertionFailure
(
what_arg
)
{
}
};
}
// namespace paramter
}
// namespace error
}
// namespace onnx_import
}
// namespace ngraph
#define ASSERT_IS_SUPPORTED(node_, cond_) \
NGRAPH_ASSERT_STREAM(ngraph::onnx_import::error::NotSupported, cond_) << (node_) << " "
#define ASSERT_VALID_ARGUMENT(node_, cond_) \
NGRAPH_ASSERT_STREAM(ngraph::onnx_import::error::InvalidArgument, cond_) << (node_) << " "
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/op/batch_norm.cpp
View file @
189cf3b7
...
...
@@ -44,18 +44,8 @@ namespace ngraph
// float momentum{node.get_attribute_value<float>("momentum", 0.9f)};
bool
training
=
false
;
if
(
!
is_test
)
{
throw
error
::
NotSupported
(
"BatchNormalization"
,
node
.
get_name
(),
"only 'is_test' mode is currently supported."
);
}
if
(
!
spatial
)
{
throw
error
::
NotSupported
(
"BatchNormalization"
,
node
.
get_name
(),
"only 'spatial' mode is currently supported."
);
}
ASSERT_IS_SUPPORTED
(
node
,
is_test
)
<<
"only 'is_test' mode is supported."
;
ASSERT_IS_SUPPORTED
(
node
,
spatial
)
<<
"only 'spatial' mode is supported."
;
if
(
inputs
.
size
()
>=
5
)
{
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/op/conv.cpp
View file @
189cf3b7
...
...
@@ -108,15 +108,10 @@ namespace ngraph
int64_t
groups
{
node
.
get_attribute_value
<
int64_t
>
(
"group"
,
1
)};
// TODO: update to ASSERTION CHECK
if
(
groups
<
0
||
groups
>
data
->
get_shape
().
at
(
1
)
||
groups
>
filters
->
get_shape
().
at
(
0
))
{
throw
error
::
parameter
::
Value
{
"Conv"
,
node
.
get_name
(),
"incorrect value of 'group' attribute: "
+
std
::
to_string
(
groups
)};
}
ASSERT_VALID_ARGUMENT
(
node
,
((
groups
>=
0
)
&&
(
groups
<=
data
->
get_shape
().
at
(
1
))
&&
(
groups
<=
filters
->
get_shape
().
at
(
0
))))
<<
"incorrect value of 'group' attribute: "
<<
groups
;
auto
strides
=
convpool
::
get_strides
(
node
);
auto
dilations
=
convpool
::
get_dilations
(
node
);
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/op/flatten.cpp
View file @
189cf3b7
...
...
@@ -31,12 +31,8 @@ namespace ngraph
auto
data
=
inputs
.
at
(
0
);
auto
axis
=
node
.
get_attribute_value
<
int64_t
>
(
"axis"
,
1
);
if
(
axis
<
0
||
axis
>
data
->
get_shape
().
size
())
{
throw
error
::
parameter
::
Value
(
"Flatten node ("
,
node
.
get_name
(),
"): provided axis attribute is not valid."
);
}
ASSERT_VALID_ARGUMENT
(
node
,
(
axis
>=
0
)
&&
(
axis
<=
data
->
get_shape
().
size
()))
<<
"provided 'axis' attribute is not valid."
;
return
{
reshape
::
flatten
(
data
,
axis
)};
}
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/op/reshape.cpp
View file @
189cf3b7
...
...
@@ -45,20 +45,13 @@ namespace ngraph
if
(
output_shape
.
empty
()
&&
ng_inputs
.
size
()
==
2
)
{
// Currently only support Constant node.
if
(
ng_inputs
.
at
(
1
)
->
description
()
==
"Constant"
)
{
ASSERT_IS_SUPPORTED
(
node
,
ng_inputs
.
at
(
1
)
->
description
()
==
"Constant"
)
<<
"doesn't support shape input of other type than Constant."
;
auto
output_shape_node
=
std
::
dynamic_pointer_cast
<
ngraph
::
op
::
Constant
>
(
ng_inputs
.
at
(
1
));
output_shape
=
output_shape_node
->
get_vector
<
std
::
size_t
>
();
}
else
{
throw
error
::
NotSupported
(
"Reshape"
,
node
.
get_name
(),
"doesn't support "
"shape input of other type than Constant."
);
}
}
// Do nothing if there is no shape argument nor second node input.
else
if
(
output_shape
.
empty
())
{
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/op/softmax.cpp
View file @
189cf3b7
...
...
@@ -39,13 +39,11 @@ namespace ngraph
{
axis
=
data_shape
.
size
()
+
axis
;
}
else
if
(
axis
>=
data_shape
.
size
())
{
throw
error
::
parameter
::
Value
(
"Softmax node ("
,
node
.
get_name
(),
"): provided axis attribute is out of input tensor dimensions range."
);
}
ASSERT_VALID_ARGUMENT
(
node
,
axis
<
data_shape
.
size
())
<<
"provided 'axis' value:"
<<
axis
<<
" is out of input tensor dimensions range."
;
// create vector of capacity data_dimensions - axis_divider position
std
::
vector
<
size_t
>
axes
(
data_shape
.
size
()
-
axis
);
std
::
iota
(
std
::
begin
(
axes
),
std
::
end
(
axes
),
axis
);
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/op/unsqueeze.cpp
View file @
189cf3b7
...
...
@@ -34,22 +34,18 @@ namespace ngraph
auto
data
=
inputs
.
at
(
0
);
auto
data_shape
=
data
->
get_shape
();
auto
axes
=
node
.
get_attribute_value
<
std
::
vector
<
int64_t
>>
(
"axes"
);
if
(
axes
.
empty
())
{
throw
error
::
parameter
::
Value
(
"Unsqueeze"
,
node
.
get_name
(),
"axes attribute is mandatory."
);
}
ASSERT_VALID_ARGUMENT
(
node
,
!
axes
.
empty
())
<<
"'axes' attribute is mandatory."
;
std
::
sort
(
std
::
begin
(
axes
),
std
::
end
(
axes
),
std
::
greater
<
int64_t
>
());
AxisVector
input_order
{
reshape
::
get_default_axis_vector
(
data_shape
.
size
())};
for
(
auto
axis
:
axes
)
{
if
((
axis
<
0
)
||
(
axis
>
data_shape
.
size
()))
{
throw
error
::
parameter
::
Value
(
"Unsqueeze"
,
node
.
get_name
(),
"provided axes attribute is not valid."
);
}
ASSERT_VALID_ARGUMENT
(
node
,
axis
>=
0
&&
axis
<=
data_shape
.
size
())
<<
"provided 'axes' attribute is not valid."
;
data_shape
.
insert
(
std
::
next
(
std
::
begin
(
data_shape
),
axis
),
1
);
}
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/utils/reduction.hpp
View file @
189cf3b7
...
...
@@ -76,15 +76,11 @@ namespace ngraph
auto
data_shape
=
ng_input
->
get_shape
();
auto
reduction_axes
=
detail
::
get_reduction_axes
(
node
);
if
(
reduction_axes
.
size
()
>
data_shape
.
size
())
{
throw
error
::
parameter
::
Value
(
node
.
op_type
(),
node
.
get_name
(),
"provided reduction axes count ("
+
std
::
to_string
(
reduction_axes
.
size
())
+
") is larger than input tensor rank ("
+
std
::
to_string
(
data_shape
.
size
())
+
")"
);
}
ASSERT_VALID_ARGUMENT
(
node
,
reduction_axes
.
size
()
<=
data_shape
.
size
())
<<
"provided reduction axes count ("
<<
reduction_axes
.
size
()
<<
") is larger than input tensor rank ("
<<
data_shape
.
size
()
<<
")"
;
auto
op_node
=
std
::
make_shared
<
OnnxOperator
>
(
ng_input
,
reduction_axes
);
std
::
int64_t
keepdims
=
node
.
get_attribute_value
<
std
::
int64_t
>
(
"keepdims"
,
1
);
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/frontend/onnx_import/utils/reshape.cpp
View file @
189cf3b7
...
...
@@ -76,19 +76,13 @@ namespace ngraph
{
if
(
inferred_dims
.
at
(
idx
)
==
0
)
{
if
(
idx
<
input_shape
.
size
())
{
NGRAPH_ASSERT
(
idx
<
input_shape
.
size
())
<<
"Node "
<<
node_name
<<
" cannot copy dimension from the input data shape because "
"requested index is out of range."
;
inferred_dims
.
at
(
idx
)
=
input_shape
.
at
(
idx
);
}
else
{
throw
error
::
parameter
::
Value
(
"Reshape"
,
node_name
,
"can not copy dimension from the input data shape since requested "
"index is out of range."
);
}
}
}
// Check whether there are dimensions equal to -1 in output_shape. There may be at most
...
...
@@ -99,14 +93,10 @@ namespace ngraph
if
(
neg_value_it
!=
std
::
end
(
inferred_dims
))
{
// only single '-1' value is allowed
if
(
std
::
find
(
std
::
next
(
neg_value_it
),
std
::
end
(
inferred_dims
),
-
1
)
!
=
NGRAPH_ASSERT
(
std
::
find
(
std
::
next
(
neg_value_it
),
std
::
end
(
inferred_dims
),
-
1
)
=
=
std
::
end
(
inferred_dims
))
{
throw
error
::
parameter
::
Value
(
"Reshape"
,
node_name
,
"more than one dimension is set to (-1). "
"Only one dimension value can be inferred."
);
}
<<
"Node "
<<
node_name
<<
" more than one dimension is set to (-1). "
<<
"Only one dimension value can be inferred."
;
// Set dimension value to 1 temporarily to be able to calculate its value.
*
neg_value_it
=
1
;
...
...
This diff is collapsed.
Click to expand it.
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