Commit 45e4e893 authored by Tomasz Dołbniak's avatar Tomasz Dołbniak Committed by Scott Cyphers

[ONNX] Erf op support (#2763)

* [ONNX] Erf op support

* [ONNX] Missing CMakeLists entry for the Erf op

* [ONNX] model_erf unit test excluded from GPU

* Update quoting style to fix errors raised by updated version of flake8.
parent c8609f3a
......@@ -43,7 +43,7 @@ class Runtime:
self.backend = Backend.create(backend_name)
def __repr__(self): # type: () -> str
return '<Runtime: Backend=\'{}\'>'.format(self.backend_name)
return "<Runtime: Backend='{}'>".format(self.backend_name)
def computation(self, node_or_function, *inputs):
# type: (Union[Node, Function], *Node) -> 'Computation'
......@@ -120,7 +120,7 @@ class Computation(object):
# type: (np.ndarray, Tensor) -> None
tensor_view_dtype = get_dtype(tensor_view.element_type)
if list(tensor_view.shape) != list(value.shape) and len(value.shape) > 0:
raise UserInputError('Provided tensor\'s shape: %s does not match the expected: %s.',
raise UserInputError("Provided tensor's shape: %s does not match the expected: %s.",
list(value.shape), list(tensor_view.shape))
if value.dtype != tensor_view_dtype:
log.warning(
......
......@@ -381,7 +381,7 @@ with open(os.path.join(PYNGRAPH_ROOT_DIR, 'requirements.txt')) as req:
setup(
name='ngraph-core',
description='nGraph - Intel\'s graph compiler and runtime for Neural Networks',
description="nGraph - Intel's graph compiler and runtime for Neural Networks",
version=__version__,
author='Intel Corporation',
author_email='intelnervana@intel.com',
......
......@@ -81,6 +81,7 @@ add_library(onnx_import STATIC
op/elu.cpp
op/elu.hpp
op/equal.hpp
op/erf.hpp
op/exp.hpp
op/flatten.cpp
op/flatten.hpp
......
//*****************************************************************************
// 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 <memory>
#include "core/node.hpp"
#include "ngraph/node_vector.hpp"
#include "ngraph/op/erf.hpp"
namespace ngraph
{
namespace onnx_import
{
namespace op
{
namespace set_1
{
inline NodeVector erf(const Node& node)
{
return {std::make_shared<ngraph::op::Erf>(node.get_ng_inputs().at(0))};
}
} // namespace set_1
} //namespace op
} // namespace onnx_import
} // namespace ngraph
......@@ -50,6 +50,7 @@
#include "op/dropout.hpp"
#include "op/elu.hpp"
#include "op/equal.hpp"
#include "op/erf.hpp"
#include "op/exp.hpp"
#include "op/flatten.hpp"
#include "op/floor.hpp"
......@@ -250,6 +251,7 @@ namespace ngraph
REGISTER_OPERATOR("Dropout", 1, dropout);
REGISTER_OPERATOR("Elu", 1, elu);
REGISTER_OPERATOR("Equal", 1, equal);
REGISTER_OPERATOR("Erf", 1, erf);
REGISTER_OPERATOR("Exp", 1, exp);
REGISTER_OPERATOR("Flatten", 1, flatten);
REGISTER_OPERATOR("Floor", 1, floor);
......
......@@ -136,3 +136,4 @@ create_tensor_2_output
# Not implemented
erf
zero_sized_erf
model_erf
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "Erf"
}
name: "erf_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 2
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 2
}
}
}
}
}
}
opset_import {
version: 9
}
......@@ -2827,4 +2827,25 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, model_quant_conv_linear_3d)
read_binary_file<uint8_t>(file_util::path_join(TEST_FILES, "onnx/qlinearconv3d/y.bin")));
EXPECT_EQ(expected_output.front(), outputs.front());
}
\ No newline at end of file
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_erf)
{
const auto function =
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/erf.prototxt"));
Inputs inputs;
inputs.emplace_back(test::NDArray<float, 2>{
{-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()},
{-3.141592f, 0.0f},
{0.5f, 1.0f}}.get_vector());
const std::vector<float> expected_outputs = test::NDArray<float, 2>{
{-1.0f, 1.0f},
{-0.99999112f, 0.0f},
{0.52049988f, 0.84270079f}}.get_vector();
const Outputs outputs{execute(function, inputs, "${BACKEND_NAME}")};
EXPECT_TRUE(test::all_close_f(expected_outputs, outputs.front()));
}
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