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
d5a5496f
Commit
d5a5496f
authored
Jun 28, 2019
by
Leona C
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into leona/doc_igpu
parents
0d7fa1b2
c36e4980
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
746 additions
and
53 deletions
+746
-53
CODEOWNERS
CODEOWNERS
+5
-5
CMakeLists.txt
src/ngraph/frontend/onnx_import/CMakeLists.txt
+5
-0
exceptions.cpp
src/ngraph/frontend/onnx_import/exceptions.cpp
+38
-0
exceptions.hpp
src/ngraph/frontend/onnx_import/exceptions.hpp
+24
-0
instance_norm.cpp
src/ngraph/frontend/onnx_import/op/instance_norm.cpp
+95
-0
instance_norm.hpp
src/ngraph/frontend/onnx_import/op/instance_norm.hpp
+47
-0
lp_norm.cpp
src/ngraph/frontend/onnx_import/op/lp_norm.cpp
+66
-0
lp_norm.hpp
src/ngraph/frontend/onnx_import/op/lp_norm.hpp
+48
-0
lp_pool.cpp
src/ngraph/frontend/onnx_import/op/lp_pool.cpp
+1
-0
lp_pool.hpp
src/ngraph/frontend/onnx_import/op/lp_pool.hpp
+0
-2
supported_ops.md
src/ngraph/frontend/onnx_import/op/supported_ops.md
+2
-4
ops_bridge.cpp
src/ngraph/frontend/onnx_import/ops_bridge.cpp
+4
-0
unit_test.manifest
src/ngraph/runtime/gpu/unit_test.manifest
+2
-0
CMakeLists.txt
test/CMakeLists.txt
+2
-0
backend_binary_elementwise.in.cpp
test/backend_binary_elementwise.in.cpp
+10
-0
backend_test.in.cpp
test/backend_test.in.cpp
+37
-9
backend_unary_elementwise.in.cpp
test/backend_unary_elementwise.in.cpp
+10
-0
instance_norm.prototxt
test/models/onnx/instance_norm.prototxt
+92
-0
lp_norm_default.prototxt
test/models/onnx/lp_norm_default.prototxt
+51
-0
lp_norm_p1.prototxt
test/models/onnx/lp_norm_p1.prototxt
+61
-0
lp_norm_p2.prototxt
test/models/onnx/lp_norm_p2.prototxt
+61
-0
onnx_import.in.cpp
test/onnx/onnx_import.in.cpp
+85
-33
No files found.
CODEOWNERS
View file @
d5a5496f
...
...
@@ -44,12 +44,12 @@ project/doc-contributor-README.rst @indie
/src/ngraph/op/ @diyessi @aprocter
/src/ngraph/op/allreduce.*pp @wenzhe-nrv @diyessi @aprocter
/src/ngraph/op/experimental/layers @ilyachur
/src/ngraph/pass/ @
jbobba
/src/ngraph/pattern/ @
jbobba @
aprocter
/src/ngraph/runtime/ @rkimballn1
@jbobba
/src/ngraph/runtime/cpu/ @
jbobb
a
/src/ngraph/pass/ @
diyessi
/src/ngraph/pattern/ @aprocter
/src/ngraph/runtime/ @rkimballn1
/src/ngraph/runtime/cpu/ @
nmostaf
a
/src/contrib/mlir/ @nmostafa @dcaballe
/src/ngraph/runtime/cpu/builder/allreduce.*pp @wenzhe-nrv @
jbobb
a @avijit-nervana
/src/ngraph/runtime/cpu/builder/allreduce.*pp @wenzhe-nrv @
nmostaf
a @avijit-nervana
/src/ngraph/runtime/dynamic/ @aprocter
/src/ngraph/runtime/gpu/ @rkimballn1
/src/ngraph/runtime/hybrid/ @rkimballn1
...
...
src/ngraph/frontend/onnx_import/CMakeLists.txt
View file @
d5a5496f
...
...
@@ -37,6 +37,7 @@ add_library(onnx_import STATIC
core/operator_set.hpp
core/tensor.hpp
core/value_info.hpp
exceptions.cpp
exceptions.hpp
op/acos.hpp
op/acosh.cpp
...
...
@@ -103,11 +104,15 @@ add_library(onnx_import STATIC
op/hardmax.cpp
op/hardmax.hpp
op/identity.hpp
op/instance_norm.cpp
op/instance_norm.hpp
op/leaky_relu.cpp
op/leaky_relu.hpp
op/less.hpp
op/log.hpp
op/log_softmax.hpp
op/lp_norm.cpp
op/lp_norm.hpp
op/lp_pool.cpp
op/lp_pool.hpp
op/lrn.cpp
...
...
src/ngraph/frontend/onnx_import/exceptions.cpp
0 → 100644
View file @
d5a5496f
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <sstream>
#include "exceptions.hpp"
namespace
ngraph
{
namespace
onnx_import
{
namespace
error
{
namespace
detail
{
std
::
string
get_error_msg_prefix
(
const
Node
&
node
)
{
std
::
stringstream
ss
;
ss
<<
"While validating ONNX node '"
<<
node
<<
"'"
;
return
ss
.
str
();
}
}
}
}
}
src/ngraph/frontend/onnx_import/exceptions.hpp
View file @
d5a5496f
...
...
@@ -16,7 +16,11 @@
#pragma once
#include <string>
#include "core/node.hpp"
#include "ngraph/assertion.hpp"
#include "ngraph/check.hpp"
#include "ngraph/except.hpp"
namespace
ngraph
...
...
@@ -25,6 +29,11 @@ namespace ngraph
{
namespace
error
{
namespace
detail
{
std
::
string
get_error_msg_prefix
(
const
Node
&
node
);
}
struct
NotSupported
:
AssertionFailure
{
explicit
NotSupported
(
const
std
::
string
&
what_arg
)
...
...
@@ -41,6 +50,17 @@ namespace ngraph
}
};
class
NodeValidationFailure
:
public
CheckFailure
{
public
:
NodeValidationFailure
(
const
CheckLocInfo
&
check_loc_info
,
const
Node
&
node
,
const
std
::
string
&
explanation
)
:
CheckFailure
(
check_loc_info
,
detail
::
get_error_msg_prefix
(
node
),
explanation
)
{
}
};
}
// namespace error
}
// namespace onnx_import
...
...
@@ -54,3 +74,7 @@ namespace ngraph
NGRAPH_ASSERT_STREAM_DO_NOT_USE_IN_NEW_CODE(ngraph::onnx_import::error::InvalidArgument, \
cond_) \
<< (node_) << " "
#define CHECK_VALID_NODE(node_, cond_, ...) \
NGRAPH_CHECK_HELPER( \
::ngraph::onnx_import::error::NodeValidationFailure, (node_), (cond_), ##__VA_ARGS__)
src/ngraph/frontend/onnx_import/op/instance_norm.cpp
0 → 100644
View file @
d5a5496f
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <cmath>
#include <cstddef>
#include "exceptions.hpp"
#include "instance_norm.hpp"
#include "ngraph/axis_set.hpp"
#include "ngraph/builder/reduce_ops.hpp"
#include "ngraph/op/add.hpp"
#include "ngraph/op/broadcast.hpp"
#include "ngraph/op/constant.hpp"
#include "ngraph/op/divide.hpp"
#include "ngraph/op/divide.hpp"
#include "ngraph/op/multiply.hpp"
#include "ngraph/op/sqrt.hpp"
#include "ngraph/op/subtract.hpp"
#include "ngraph/op/util/broadcasting.hpp"
#include "utils/common.hpp"
namespace
ngraph
{
namespace
onnx_import
{
namespace
op
{
namespace
set_1
{
NodeVector
instance_norm
(
const
Node
&
node
)
{
const
std
::
shared_ptr
<
ngraph
::
Node
>
data
{
node
.
get_ng_inputs
().
at
(
0
)};
std
::
shared_ptr
<
ngraph
::
Node
>
scale
{
node
.
get_ng_inputs
().
at
(
1
)};
std
::
shared_ptr
<
ngraph
::
Node
>
bias
{
node
.
get_ng_inputs
().
at
(
2
)};
const
float
epsilon
{
node
.
get_attribute_value
<
float
>
(
"epsilon"
,
1e-5
f
)};
CHECK_VALID_NODE
(
node
,
(
scale
->
get_shape
().
size
()
==
1
&&
scale
->
get_shape
()[
0
]
==
data
->
get_shape
().
at
(
1
)),
"Scale input must be one dimensional vector of number of "
"input data channels size."
);
CHECK_VALID_NODE
(
node
,
(
bias
->
get_shape
().
size
()
==
1
&&
bias
->
get_shape
()[
0
]
==
data
->
get_shape
().
at
(
1
)),
"Bias input must be one dimensional vector of number of "
"input data channels size."
);
// all dimensions except spatial/feature
const
AxisSet
reduction_axes
{
common
::
get_monotonic_range
<
std
::
size_t
>
(
data
->
get_shape
().
size
(),
2
)};
const
std
::
shared_ptr
<
ngraph
::
Node
>
eps_node
=
std
::
make_shared
<
ngraph
::
op
::
Constant
>
(
data
->
get_element_type
(),
data
->
get_shape
(),
std
::
vector
<
float
>
{
epsilon
});
scale
=
ngraph
::
op
::
legacy_style_broadcast_for_binary_operation
(
data
,
scale
,
1
)
.
at
(
1
);
bias
=
ngraph
::
op
::
legacy_style_broadcast_for_binary_operation
(
data
,
bias
,
1
)
.
at
(
1
);
std
::
shared_ptr
<
ngraph
::
Node
>
mean
=
builder
::
mean
(
data
,
reduction_axes
);
mean
=
std
::
make_shared
<
ngraph
::
op
::
Broadcast
>
(
mean
,
data
->
get_shape
(),
reduction_axes
);
std
::
shared_ptr
<
ngraph
::
Node
>
variance
=
builder
::
variance
(
data
,
reduction_axes
);
variance
=
std
::
make_shared
<
ngraph
::
op
::
Broadcast
>
(
variance
,
data
->
get_shape
(),
reduction_axes
);
const
auto
sqrt
=
std
::
make_shared
<
ngraph
::
op
::
Sqrt
>
(
variance
+
eps_node
);
return
{
scale
*
(
data
-
mean
)
/
sqrt
+
bias
};
}
}
// namespace set_1
}
//namespace op
}
// namespace onnx_import
}
// namespace ngraph
src/ngraph/frontend/onnx_import/op/instance_norm.hpp
0 → 100644
View file @
d5a5496f
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
#include "core/node.hpp"
#include "ngraph/node.hpp"
namespace
ngraph
{
namespace
onnx_import
{
namespace
op
{
namespace
set_1
{
/// \brief Creates nGraph node representing ONNX InstanceNormalization operator.
///
/// \note The resulting node represents following equation:
/// y = scale * (x - mean) / sqrt(variance + epsilon) + B
/// where mean and variance are computed per instance per channel.
///
/// \param[in] node The input ONNX node representing this operation.
///
/// \return Vector of nodes containting resulting nGraph nodes.
///
NodeVector
instance_norm
(
const
Node
&
node
);
}
// namespace set_1
}
//namespace op
}
// namespace onnx_import
}
// namespace ngraph
src/ngraph/frontend/onnx_import/op/lp_norm.cpp
0 → 100644
View file @
d5a5496f
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <cmath>
#include <cstddef>
#include <cstdint>
#include "exceptions.hpp"
#include "lp_norm.hpp"
#include "ngraph/axis_set.hpp"
#include "ngraph/builder/norm.hpp"
#include "ngraph/op/broadcast.hpp"
#include "ngraph/op/divide.hpp"
namespace
ngraph
{
namespace
onnx_import
{
namespace
op
{
namespace
set_1
{
NodeVector
lp_norm
(
const
Node
&
node
)
{
const
std
::
shared_ptr
<
ngraph
::
Node
>
data
{
node
.
get_ng_inputs
().
at
(
0
)};
std
::
int64_t
axis
{
node
.
get_attribute_value
<
std
::
int64_t
>
(
"axis"
,
-
1
)};
const
std
::
int64_t
p_norm
{
node
.
get_attribute_value
<
std
::
int64_t
>
(
"p"
,
2
)};
if
(
axis
<
0
)
{
axis
+=
data
->
get_shape
().
size
();
}
ASSERT_VALID_ARGUMENT
(
node
,
p_norm
==
1
||
p_norm
==
2
)
<<
"Invalid `p` attribute value: "
<<
p_norm
<<
"Only normalization of 1st or 2nd order is supported."
;
const
AxisSet
reduction_axes
{
static_cast
<
std
::
size_t
>
(
axis
)};
std
::
shared_ptr
<
ngraph
::
Node
>
norm
=
ngraph
::
builder
::
lp_norm
(
data
,
reduction_axes
,
static_cast
<
std
::
size_t
>
(
p_norm
));
norm
=
std
::
make_shared
<
ngraph
::
op
::
Broadcast
>
(
norm
,
data
->
get_shape
(),
reduction_axes
);
return
{
data
/
norm
};
}
}
// namespace set_1
}
//namespace op
}
// namespace onnx_import
}
// namespace ngraph
src/ngraph/frontend/onnx_import/op/lp_norm.hpp
0 → 100644
View file @
d5a5496f
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
#include "core/node.hpp"
#include "ngraph/node.hpp"
namespace
ngraph
{
namespace
onnx_import
{
namespace
op
{
namespace
set_1
{
/// \brief Creates nGraph node representing ONNX LpNormalization operator.
///
/// Suppose A contains spatial dimensions of input tensor, then
/// for matrix A we have p-norm defined as following double sum over
/// all elements:
/// ||A||_p = ||vec(A)||_p = [sum_{i=1}^m sum_{j=1}^n abs(a_{i,j})^p]^{1/p}
///
/// \param[in] node The input ONNX node representing this operation.
///
/// \return Vector of nodes containting resulting nGraph nodes.
///
NodeVector
lp_norm
(
const
Node
&
node
);
}
// namespace set_1
}
//namespace op
}
// namespace onnx_import
}
// namespace ngraph
src/ngraph/frontend/onnx_import/op/lp_pool.cpp
View file @
d5a5496f
...
...
@@ -17,6 +17,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <memory>
#include "exceptions.hpp"
#include "lp_pool.hpp"
...
...
src/ngraph/frontend/onnx_import/op/lp_pool.hpp
View file @
d5a5496f
...
...
@@ -16,8 +16,6 @@
#pragma once
#include <memory>
#include "core/node.hpp"
#include "ngraph/node.hpp"
...
...
src/ngraph/frontend/onnx_import/op/supported_ops.md
View file @
d5a5496f
...
...
@@ -53,11 +53,13 @@ opset versions starting from `1` to `6` and to the latest opset version.
| Greater | 1-7-9 |
| HardSigmoid | 1-6- |
| Identity | 1- |
| InstanceNormalization | 1- |
| LRN | 1- |
| LeakyRelu | 1-6- |
| Less | 1-7-9 |
| Log | 1-6- |
| LogSoftmax | 1- |
| LpNormalization | 1- |
| MatMul | 1-9 |
| Max | 1-6-8- |
| MaxPool | 1-8- |
...
...
@@ -153,8 +155,4 @@ opset versions starting from `1` to `6` and to the latest opset version.
|------|-----------------|--------|--------|---------|
| Add, Sub, Mul, Div | 1-6 | | | We currently don't support legacy broadcasting rules for binary ops. |
| Cast | 1-6- | | 427 | Errors while casting to bool |
| EyeLike | (9) | | 439 | Make constant node. |
| Hardmax | - | | 431 | Use make constant and Argmax. See
`test_ops_unary.py::test_hardmax()`
|
| LpNormalization | - | | 436 | Just an equation. Only Lp{1,2} need to be supported. |
| InstanceNormalization | - | | 436 | Just an equation. For per channel computation may _slice/op/concat_ pattern need to be used. |
| Shrink | (9) | | 449 | Just an easy equation. |
src/ngraph/frontend/onnx_import/ops_bridge.cpp
View file @
d5a5496f
...
...
@@ -64,10 +64,12 @@
#include "op/hard_sigmoid.hpp"
#include "op/hardmax.hpp"
#include "op/identity.hpp"
#include "op/instance_norm.hpp"
#include "op/leaky_relu.hpp"
#include "op/less.hpp"
#include "op/log.hpp"
#include "op/log_softmax.hpp"
#include "op/lp_norm.hpp"
#include "op/lp_pool.hpp"
#include "op/lrn.hpp"
#include "op/lstm.hpp"
...
...
@@ -273,10 +275,12 @@ namespace ngraph
REGISTER_OPERATOR
(
"Hardmax"
,
1
,
hardmax
);
REGISTER_OPERATOR
(
"HardSigmoid"
,
1
,
hard_sigmoid
);
REGISTER_OPERATOR
(
"Identity"
,
1
,
identity
);
REGISTER_OPERATOR
(
"InstanceNormalization"
,
1
,
instance_norm
);
REGISTER_OPERATOR
(
"LeakyRelu"
,
1
,
leaky_relu
);
REGISTER_OPERATOR
(
"Less"
,
1
,
less
);
REGISTER_OPERATOR
(
"Log"
,
1
,
log
);
REGISTER_OPERATOR
(
"LogSoftmax"
,
1
,
log_softmax
);
REGISTER_OPERATOR
(
"LpNormalization"
,
1
,
lp_norm
);
REGISTER_OPERATOR
(
"LRN"
,
1
,
lrn
);
REGISTER_OPERATOR
(
"LSTM"
,
1
,
lstm
);
REGISTER_OPERATOR
(
"MatMul"
,
1
,
matmul
);
...
...
src/ngraph/runtime/gpu/unit_test.manifest
View file @
d5a5496f
...
...
@@ -4,6 +4,8 @@ computation_reuse
dot_matrix_vector_int64
generate_mask
generate_mask2
# Gives inaccurate value
sigmoid_bprop_n1c1h4
# custom_mem is not implemented on GPU
tensorview_custom_mem
# integer is not supported by cuDNN on backward pooling
...
...
test/CMakeLists.txt
View file @
d5a5496f
...
...
@@ -261,6 +261,8 @@ endif()
if
(
NGRAPH_PLAIDML_ENABLE
)
target_link_libraries
(
unit-test PRIVATE plaidml_backend
)
# Some PlaidML devices aren't so precise, so we increase the allowable tolerance.
target_compile_definitions
(
unit-test PRIVATE
"PlaidML_FLOAT_TOLERANCE_BITS=12"
)
endif
()
if
(
NGRAPH_TBB_ENABLE
)
...
...
test/backend_binary_elementwise.in.cpp
View file @
d5a5496f
...
...
@@ -21,6 +21,16 @@
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
...
...
test/backend_test.in.cpp
View file @
d5a5496f
...
...
@@ -22,6 +22,16 @@
#include <string>
#include "gtest/gtest.h"
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "ngraph/autodiff/adjoints.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
...
...
@@ -5184,12 +5194,17 @@ NGRAPH_TEST(${BACKEND_NAME}, sigmoid_n1c1h2w2)
shared_ptr
<
runtime
::
Tensor
>
a
=
backend
->
create_tensor
(
element
::
f32
,
input
->
get_shape
());
shared_ptr
<
runtime
::
Tensor
>
result
=
backend
->
create_tensor
(
element
::
f32
,
input
->
get_shape
());
vector
<
float
>
dataA
{
1.0
f
,
4.0
f
,
1.0
f
,
4.0
f
};
float
x1
=
1.0
f
;
float
x2
=
4.0
f
;
float
sigma1
=
1.0
f
/
(
1.0
f
+
std
::
exp
(
-
x1
));
float
sigma2
=
1.0
f
/
(
1.0
f
+
std
::
exp
(
-
x2
));
vector
<
float
>
dataA
{
x1
,
x2
,
x1
,
x2
};
copy_data
(
a
,
dataA
);
auto
handle
=
backend
->
compile
(
func
);
handle
->
call_with_validate
({
result
},
{
a
});
vector
<
float
>
expected
{
0.73105858
f
,
0.98201379
f
,
0.73105858
f
,
0.98201379
f
};
vector
<
float
>
expected
{
sigma1
,
sigma2
,
sigma1
,
sigma2
};
EXPECT_TRUE
(
test
::
all_close_f
(
read_vector
<
float
>
(
result
),
expected
));
}
...
...
@@ -5204,12 +5219,17 @@ NGRAPH_TEST(${BACKEND_NAME}, sigmoid_n1c1h4)
shared_ptr
<
runtime
::
Tensor
>
a
=
backend
->
create_tensor
(
element
::
f32
,
input
->
get_shape
());
shared_ptr
<
runtime
::
Tensor
>
result
=
backend
->
create_tensor
(
element
::
f32
,
input
->
get_shape
());
vector
<
float
>
dataA
{
1.0
f
,
4.0
f
,
1.0
f
,
4.0
f
};
float
x1
=
1.0
f
;
float
x2
=
4.0
f
;
float
sigma1
=
1.0
f
/
(
1.0
f
+
std
::
exp
(
-
x1
));
float
sigma2
=
1.0
f
/
(
1.0
f
+
std
::
exp
(
-
x2
));
vector
<
float
>
dataA
{
x1
,
x2
,
x1
,
x2
};
copy_data
(
a
,
dataA
);
auto
handle
=
backend
->
compile
(
func
);
handle
->
call_with_validate
({
result
},
{
a
});
vector
<
float
>
expected
{
0.73105858
f
,
0.98201379
f
,
0.73105858
f
,
0.98201379
f
};
vector
<
float
>
expected
{
sigma1
,
sigma2
,
sigma1
,
sigma2
};
EXPECT_TRUE
(
test
::
all_close_f
(
read_vector
<
float
>
(
result
),
expected
));
}
...
...
@@ -5225,16 +5245,24 @@ NGRAPH_TEST(${BACKEND_NAME}, sigmoid_bprop_n1c1h4)
shared_ptr
<
runtime
::
Tensor
>
b
=
backend
->
create_tensor
(
element
::
f32
,
delta
->
get_shape
());
shared_ptr
<
runtime
::
Tensor
>
result
=
backend
->
create_tensor
(
element
::
f32
,
input
->
get_shape
());
vector
<
float
>
dataA
{
1.0
f
,
4.0
f
,
1.0
f
,
4.0
f
};
vector
<
float
>
dataB
{
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
};
float
x1
=
1.0
f
;
float
x2
=
4.0
f
;
float
dt
=
1.0
f
;
float
sigma1
=
1.0
f
/
(
1.0
f
+
std
::
exp
(
-
x1
));
float
sigma2
=
1.0
f
/
(
1.0
f
+
std
::
exp
(
-
x2
));
float
bprop1
=
sigma1
*
(
1
-
sigma1
)
*
dt
;
float
bprop2
=
sigma2
*
(
1
-
sigma2
)
*
dt
;
vector
<
float
>
dataA
{
x1
,
x2
,
x1
,
x2
};
vector
<
float
>
dataB
{
dt
,
dt
,
dt
,
dt
};
copy_data
(
a
,
dataA
);
copy_data
(
b
,
dataB
);
auto
handle
=
backend
->
compile
(
func
);
handle
->
call_with_validate
({
result
},
{
a
,
b
});
vector
<
float
>
expected
{
0.196612
f
,
0.0176627
f
,
0.196612
f
,
0.0176627
f
};
EXPECT_TRUE
(
test
::
all_close
(
expected
,
read_vector
<
float
>
(
result
)));
vector
<
float
>
expected
{
bprop1
,
bprop2
,
bprop1
,
bprop2
};
EXPECT_TRUE
(
test
::
all_close
_f
(
expected
,
read_vector
<
float
>
(
result
)));
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
relu_2Dfprop
)
...
...
@@ -5540,7 +5568,7 @@ NGRAPH_TEST(${BACKEND_NAME}, softmax_underflow)
handle
->
call_with_validate
({
result
},
{
a
});
vector
<
float
>
expected
{
expf
(
low
)
/
d0
,
expf
(
1
)
/
d1
,
expf
(
2
)
/
d2
,
expf
(
3
)
/
d0
,
expf
(
4
)
/
d1
,
expf
(
5
)
/
d2
};
EXPECT_TRUE
(
test
::
all_close
(
expected
,
read_vector
<
float
>
(
result
)));
EXPECT_TRUE
(
test
::
all_close
_f
(
expected
,
read_vector
<
float
>
(
result
)));
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
softmax_overflow
)
...
...
test/backend_unary_elementwise.in.cpp
View file @
d5a5496f
...
...
@@ -21,6 +21,16 @@
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
...
...
test/models/onnx/instance_norm.prototxt
0 → 100644
View file @
d5a5496f
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
input: "scale"
input: "bias"
output: "y"
op_type: "InstanceNormalization"
attribute {
name: "epsilon"
f: 0.01
type: FLOAT
}
}
name: "instance_norm_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "scale"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "bias"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 1
}
test/models/onnx/lp_norm_default.prototxt
0 → 100644
View file @
d5a5496f
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "LpNormalization"
}
name: "lp_norm_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 1
}
test/models/onnx/lp_norm_p1.prototxt
0 → 100644
View file @
d5a5496f
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "LpNormalization"
attribute {
name: "axis"
i: 0
type: INT
}
attribute {
name: "p"
i: 1
type: INT
}
}
name: "lp_norm_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 1
}
test/models/onnx/lp_norm_p2.prototxt
0 → 100644
View file @
d5a5496f
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "LpNormalization"
attribute {
name: "axis"
i: 0
type: INT
}
attribute {
name: "p"
i: 2
type: INT
}
}
name: "lp_norm_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 1
}
test/onnx/onnx_import.in.cpp
View file @
d5a5496f
...
...
@@ -20,6 +20,7 @@
#include <fstream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <stdexcept>
#include <vector>
...
...
@@ -1483,45 +1484,96 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, model_shrink_int)
test_case
.
run
();
}
NGRAPH_TEST
(
onnx_
$
{
BACKEND_NAME
},
model_lp_norm_p1
)
{
const
auto
lp_norm_fn
=
onnx_import
::
import_onnx_model
(
file_util
::
path_join
(
SERIALIZED_ZOO
,
"onnx/lp_norm_p1.prototxt"
));
Shape
data_shape
{
2
,
3
,
4
};
std
::
vector
<
float
>
data
(
shape_size
(
data_shape
));
std
::
iota
(
std
::
begin
(
data
),
std
::
end
(
data
),
1
);
auto
test_case
=
ngraph
::
test
::
NgraphTestCase
(
lp_norm_fn
,
"${BACKEND_NAME}"
);
test_case
.
add_input
<
float
>
(
data
);
test_case
.
add_expected_output
<
float
>
(
data_shape
,
{
0.07142857
f
,
0.125
f
,
0.16666667
f
,
0.2
f
,
0.22727273
f
,
0.25
f
,
0.26923078
f
,
0.2857143
f
,
0.3
f
,
0.3125
f
,
0.32352942
f
,
0.33333334
f
,
0.9285714
f
,
0.875
f
,
0.8333333
f
,
0.8
f
,
0.77272725
f
,
0.75
f
,
0.7307692
f
,
0.71428573
f
,
0.7
f
,
0.6875
f
,
0.6764706
f
,
0.6666667
f
});
test_case
.
run
();
}
NGRAPH_TEST
(
onnx_
$
{
BACKEND_NAME
},
model_lp_norm_p2
)
{
const
auto
lp_norm_fn
=
onnx_import
::
import_onnx_model
(
file_util
::
path_join
(
SERIALIZED_ZOO
,
"onnx/lp_norm_p2.prototxt"
));
Shape
data_shape
{
2
,
3
,
4
};
std
::
vector
<
float
>
data
(
shape_size
(
data_shape
));
std
::
iota
(
std
::
begin
(
data
),
std
::
end
(
data
),
1
);
auto
test_case
=
ngraph
::
test
::
NgraphTestCase
(
lp_norm_fn
,
"${BACKEND_NAME}"
);
test_case
.
add_input
<
float
>
(
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.4314555
f
,
0.4472136
f
,
0.9970545
f
,
0.98994946
f
,
0.9805807
f
,
0.97014254
f
,
0.9593655
f
,
0.9486833
f
,
0.9383431
f
,
0.9284767
f
,
0.91914505
f
,
0.9103665
f
,
0.9021342
f
,
0.8944272
f
});
test_case
.
run
();
}
NGRAPH_TEST
(
onnx_
$
{
BACKEND_NAME
},
model_lp_norm_default
)
{
const
auto
lp_norm_fn
=
onnx_import
::
import_onnx_model
(
file_util
::
path_join
(
SERIALIZED_ZOO
,
"onnx/lp_norm_default.prototxt"
));
Shape
data_shape
{
2
,
3
,
4
};
std
::
vector
<
float
>
data
(
shape_size
(
data_shape
));
std
::
iota
(
std
::
begin
(
data
),
std
::
end
(
data
),
1
);
auto
test_case
=
ngraph
::
test
::
NgraphTestCase
(
lp_norm_fn
,
"${BACKEND_NAME}"
);
test_case
.
add_input
<
float
>
(
data
);
test_case
.
add_expected_output
<
float
>
(
data_shape
,
{
0.18257418
f
,
0.36514837
f
,
0.5477225
f
,
0.73029673
f
,
0.37904903
f
,
0.45485884
f
,
0.5306686
f
,
0.60647845
f
,
0.42616236
f
,
0.47351375
f
,
0.5208651
f
,
0.5682165
f
,
0.4469492
f
,
0.48132992
f
,
0.51571065
f
,
0.5500913
f
,
0.45862272
f
,
0.48560053
f
,
0.5125783
f
,
0.53955615
f
,
0.46609157
f
,
0.4882864
f
,
0.51048124
f
,
0.5326761
f
});
test_case
.
run
();
}
NGRAPH_TEST
(
onnx_
$
{
BACKEND_NAME
},
model_instance_normalization
)
{
const
auto
instance_norm_fn
=
onnx_import
::
import_onnx_model
(
file_util
::
path_join
(
SERIALIZED_ZOO
,
"onnx/instance_norm.prototxt"
));
Shape
data_shape
{
1
,
2
,
3
,
4
};
std
::
vector
<
float
>
data
(
shape_size
(
data_shape
));
std
::
iota
(
std
::
begin
(
data
),
std
::
end
(
data
),
1
);
auto
test_case
=
ngraph
::
test
::
NgraphTestCase
(
instance_norm_fn
,
"${BACKEND_NAME}"
);
test_case
.
add_input
<
float
>
(
data
);
test_case
.
add_input
<
float
>
(
std
::
vector
<
float
>
{
2.134
f
,
3.256
f
});
test_case
.
add_input
<
float
>
(
std
::
vector
<
float
>
{
0.765
f
,
1.055
f
});
test_case
.
add_expected_output
<
float
>
(
data_shape
,
{
-
2.6335807
f
,
-
2.015657
f
,
-
1.3977331
f
,
-
0.77980936
f
,
-
0.16188562
f
,
0.45603812
f
,
1.0739619
f
,
1.6918856
f
,
2.3098092
f
,
2.927733
f
,
3.5456567
f
,
4.1635804
f
,
-
4.130463
f
,
-
3.1876516
f
,
-
2.2448401
f
,
-
1.3020288
f
,
-
0.35921717
f
,
0.5835942
f
,
1.5264057
f
,
2.469217
f
,
3.4120288
f
,
4.35484
f
,
5.2976513
f
,
6.240463
f
});
test_case
.
run
();
}
NGRAPH_TEST
(
onnx_
$
{
BACKEND_NAME
},
model_eye_like
)
{
const
auto
eye_like_fn
=
onnx_import
::
import_onnx_model
(
file_util
::
path_join
(
SERIALIZED_ZOO
,
"onnx/eye_like.prototxt"
));
auto
test_case
=
ngraph
::
test
::
NgraphTestCase
(
eye_like_fn
,
"${BACKEND_NAME}"
);
test_case
.
add_input
<
float
>
({
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
});
test_case
.
add_expected_output
<
float
>
(
Shape
{
3
,
4
},
{
0.
f
,
0.
f
,
0.
f
,
0.
f
,
1.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
1.
f
,
0.
f
,
0.
f
,
});
test_case
.
add_input
<
float
>
({
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
});
test_case
.
add_expected_output
<
float
>
(
Shape
{
3
,
4
},
{
0.
f
,
0.
f
,
0.
f
,
0.
f
,
1.
f
,
0.
f
,
0.
f
,
0.
f
,
0.
f
,
1.
f
,
0.
f
,
0.
f
});
test_case
.
run
();
}
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