MCPcopy Create free account
hub / github.com/apache/singa / _relu_helper

Method _relu_helper

test/python/test_onnx.py:78–96  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

76 self._conv2d_helper(gpu_dev)
77
78 def _relu_helper(self, dev):
79 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
80 0.5]).reshape(3, 2).astype(np.float32)
81 XT = np.array([0.8, 0, 3.3, 0, 0, 0.5]).reshape(3, 2).astype(np.float32)
82 x = tensor.from_numpy(X)
83 x.to_device(dev)
84 y = autograd.ReLU()(x)[0]
85
86 # frontend
87 model = sonnx.to_onnx([x], [y])
88 # print('The model is:\n{}'.format(model))
89
90 # backend
91 sg_ir = sonnx.prepare(model, device=dev)
92 sg_ir.is_graph = True
93 y_t = sg_ir.run([x])
94 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
95 tensor.to_numpy(y_t[0]),
96 decimal=5)
97
98 def test_relu_cpu(self):
99 self._relu_helper(cpu_dev)

Callers 2

test_relu_cpuMethod · 0.95
test_relu_gpuMethod · 0.95

Calls 4

prepareMethod · 0.80
reshapeMethod · 0.45
to_deviceMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected