Commit ba4d081c by Jon Soifer Committed by Jared Roesch

[Relay][Frontend][ONNX] Add Erf to ONNX frontend (#3988)

* Add Erf to ONNX frontend

* dummy change to retrigger CI
parent 3f7cbed8
......@@ -896,6 +896,13 @@ class Tile(Elemwise):
reps = attr.pop('repeats') # The number of times repeating the tensor data.
return _op.tile(inputs[0], reps)
class Erf(OnnxOpConverter):
"""Operator converter for Erf
"""
@classmethod
def _impl_v1(cls, inputs, attr, params):
return _op.erf(inputs[0])
# compatible operators that do NOT require any conversion.
_identity_list = []
......@@ -1015,7 +1022,8 @@ def _get_convert_map(opset):
'Equal': Equal.get_converter(opset),
'Not': Not.get_converter(opset),
'And': And.get_converter(opset),
'Tile': Tile.get_converter(opset)
'Tile': Tile.get_converter(opset),
'Erf': Erf.get_converter(opset)
}
......
......@@ -28,6 +28,7 @@ from nnvm.testing.config import ctx_list
import onnx
from onnx import helper, TensorProto
import unittest
import scipy
def get_tvm_output(graph_def, input_data, target, ctx, output_shape=None, output_dtype='float32'):
""" Generic function to execute and get tvm output"""
......@@ -1225,6 +1226,23 @@ def test_tile():
z = np.tile(x, repeats)
verify_tile(x, z, repeats=repeats)
def verify_erf(indata, outdata):
node = helper.make_node('Erf', inputs=['in'], outputs=['out'])
graph = helper.make_graph([node],
'erf_test',
inputs=[helper.make_tensor_value_info('in', TensorProto.FLOAT, list(indata.shape))],
outputs=[helper.make_tensor_value_info('out', TensorProto.FLOAT, list(outdata.shape))])
model = helper.make_model(graph, producer_name='erf_test')
for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [indata], target, ctx, outdata.shape)
tvm.testing.assert_allclose(outdata, tvm_out)
def test_erf():
x = np.random.rand(2, 3, 4, 6).astype(np.float32)
z = scipy.special.erf(x)
verify_erf(x, z)
if __name__ == '__main__':
test_flatten()
......@@ -1272,3 +1290,4 @@ if __name__ == '__main__':
test_not()
test_and()
test_tile()
test_erf()
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