Exemple #1
0
 def check_double_forward(self, x, y):
     mx = ideep4py.mdarray(x)
     x2 = numpy.array(mx)
     numpy.testing.assert_allclose(x, x2)
     my = relu.Forward(mx)
     y2 = numpy.array(my)
     numpy.testing.assert_allclose(y, y2)
     my = relu.Forward(my)
     y2 = numpy.array(my)
     numpy.testing.assert_allclose(y, y2)
 def test_sum4(self):
     x = numpy.random.rand(256, 384, 13, 13)
     x = x.astype(numpy.float32)
     y = numpy.maximum(x, 0, dtype=numpy.float32)
     mx = mdarray(x)
     my = relu.Forward(mx)
     numpy.testing.assert_allclose(my.sum((0, 2, 3)), y.sum((0, 2, 3)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((1, 2, 3)), y.sum((1, 2, 3)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((0, 1, 2)), y.sum((0, 1, 2)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((0, 2)), y.sum((0, 2)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((1, 3)), y.sum((1, 3)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((1, 2)), y.sum((1, 2)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((0)), y.sum((0)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((3)), y.sum((3)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((2)), y.sum((2)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((0, 2, 3)), y.sum((0, 2, 3)),
                                   **self.check_options)
     numpy.testing.assert_allclose(my.sum((0, 2, 3), keepdims=True),
                                   y.sum((0, 2, 3), keepdims=True),
                                   **self.check_options)
Exemple #3
0
 def test_mkldnn_format(self):
     y = numpy.maximum(self.x, 0, dtype=self.x.dtype)
     my = relu.Forward(self.mx)
     numpy.testing.assert_allclose(y, my)
     a = []
     b = []
     for p, xi in enumerate(y):
         a.append(xi)
     for p, mxi in enumerate(my):
         b.append(mxi)
     numpy.testing.assert_allclose(numpy.asarray(a), numpy.asarray(b))
Exemple #4
0
import numpy
from chainer import testing
import ideep4py
from ideep4py import relu

# x = numpy.ndarray(shape=(1,32,224,224), dtype=numpy.float32, order='C')
x = numpy.random.uniform(-1, 1, (1, 32, 224, 224)).astype(numpy.float32)
y = numpy.maximum(x, 0, dtype=x.dtype)

mx = ideep4py.mdarray(x)
x2 = numpy.array(mx)
testing.assert_allclose(x, x2)

print("Relu fwd")
my = relu.Forward(mx)
y2 = numpy.array(my)
testing.assert_allclose(y, y2)
my = relu.Forward(my)
y2 = numpy.array(my)
testing.assert_allclose(y, y2)

# Test backward
print("Relu bwd")
x = numpy.random.uniform(-1, 1, (1, 32, 224, 224)).astype(numpy.float32)
gy = numpy.random.uniform(-1, 1, (1, 32, 224, 224)).astype(numpy.float32)
gx = (x > 0) * gy

mx = ideep4py.mdarray(x)
mgy = ideep4py.mdarray(gy)
mgx = relu.Backward(mx, mgy)