Search in sources :

Example 6 with DynamicCustomOp

use of org.nd4j.linalg.api.ops.DynamicCustomOp in project nd4j by deeplearning4j.

the class ConvolutionTests method testPooling3.

@Test
public void testPooling3() {
    for (char outputOrder : new char[] { 'c', 'f' }) {
        INDArray exp = Nd4j.create(new float[] { 11.f, 12.f, 15.f, 16.f, 27.f, 28.f, 31.f, 32.f, 43.f, 44.f, 47.f, 48.f, 59.f, 60.f, 63.f, 64.f }, new int[] { 2, 2, 2, 2 }, 'c');
        int len = 2 * 4 * 4 * 2;
        INDArray x = Nd4j.linspace(1, len, len).reshape('c', 2, 4, 4, 2);
        DynamicCustomOp op = DynamicCustomOp.builder("maxpool2d").addIntegerArguments(new int[] { 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1 }).addInputs(x).addOutputs(Nd4j.create(new int[] { 2, 2, 2, 2 }, outputOrder)).build();
        Nd4j.getExecutioner().exec(op);
        INDArray out = op.getOutputArgument(0);
        assertEquals("Output order: " + outputOrder, exp, out);
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DynamicCustomOp(org.nd4j.linalg.api.ops.DynamicCustomOp) NDArrayIndex.point(org.nd4j.linalg.indexing.NDArrayIndex.point) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 7 with DynamicCustomOp

use of org.nd4j.linalg.api.ops.DynamicCustomOp in project nd4j by deeplearning4j.

the class ConvolutionTests method testPooling1.

@Test
public void testPooling1() {
    for (char outputOrder : new char[] { 'c', 'f' }) {
        INDArray exp = Nd4j.create(new float[] { 6.f, 7.f, 10.f, 11.f, 22.f, 23.f, 26.f, 27.f, 38.f, 39.f, 42.f, 43.f, 54.f, 55.f, 58.f, 59.f }, new int[] { 2, 2, 2, 2 }, 'c');
        int len = 2 * 4 * 4 * 2;
        INDArray x = Nd4j.linspace(1, len, len).reshape('c', 2, 4, 4, 2);
        DynamicCustomOp op = DynamicCustomOp.builder("avgpool2d").addIntegerArguments(// ky, kx, sy, sx, py, px, dy, dx, isSameMode, ???, divisor, nchw
        new int[] { 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1 }).addInputs(x).addOutputs(Nd4j.create(new int[] { 2, 2, 2, 2 }, outputOrder)).build();
        Nd4j.getExecutioner().exec(op);
        INDArray out = op.getOutputArgument(0);
        assertEquals("Output order: " + outputOrder, exp, out);
    /*
            k=2, s=2, p=0, d=1, same mode, divisor = 1


            //c order: strides are descending... i.e., last dimension changes quickest

            //Minibatch 0:
                //Depth 0
            [ 0,  1
              2,  3
              4,  5
              6,  7 ]

                //Depth 1
             [ 8,  9
              10, 11
              12, 13
              14, 15 ]

                //Depth 2
             [16, 17
              18, 19
              20, 21
              22, 23 ]

                //Depth 3
             [24, 25
              26, 27
              28, 29
              30, 31 ]



            //Minibatch 1:

             */
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DynamicCustomOp(org.nd4j.linalg.api.ops.DynamicCustomOp) NDArrayIndex.point(org.nd4j.linalg.indexing.NDArrayIndex.point) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 8 with DynamicCustomOp

use of org.nd4j.linalg.api.ops.DynamicCustomOp in project nd4j by deeplearning4j.

the class ConvolutionTests method testPooling5.

@Test
public void testPooling5() {
    for (char outputOrder : new char[] { 'c', 'f' }) {
        INDArray exp = Nd4j.create(new float[] { 7.f, 8.f, 11.f, 12.f, 14.f, 15.f, 27.f, 28.f, 31.f, 32.f, 34.f, 35.f, 42.f, 43.f, 46.f, 47.f, 49.f, 50.f, 57.f, 58.f, 61.f, 62.f, 64.f, 65.f, 77.f, 78.f, 81.f, 82.f, 84.f, 85.f, 92.f, 93.f, 96.f, 97.f, 99.f, 100.f }, new int[] { 2, 3, 3, 2 }, 'c');
        int len = 2 * 5 * 5 * 2;
        INDArray x = Nd4j.linspace(1, len, len).reshape('c', 2, 5, 5, 2);
        DynamicCustomOp op = DynamicCustomOp.builder("avgpool2d").addIntegerArguments(new int[] { 2, 2, 2, 2, 0, 0, 1, 1, 1, 0, 1 }).addInputs(x).addOutputs(Nd4j.create(new int[] { 2, 3, 3, 2 }, outputOrder)).build();
        Nd4j.getExecutioner().exec(op);
        INDArray out = op.getOutputArgument(0);
        assertEquals("Output order: " + outputOrder, exp, out);
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DynamicCustomOp(org.nd4j.linalg.api.ops.DynamicCustomOp) NDArrayIndex.point(org.nd4j.linalg.indexing.NDArrayIndex.point) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 9 with DynamicCustomOp

use of org.nd4j.linalg.api.ops.DynamicCustomOp in project nd4j by deeplearning4j.

the class ConvolutionTests method testPooling4.

@Test
public void testPooling4() {
    for (char outputOrder : new char[] { 'c', 'f' }) {
        INDArray exp = Nd4j.create(new float[] { 11.f, 12.f, 15.f, 16.f, 27.f, 28.f, 31.f, 32.f, 43.f, 44.f, 47.f, 48.f, 59.f, 60.f, 63.f, 64.f }, new int[] { 2, 2, 2, 2 }, 'c');
        int len = 2 * 4 * 4 * 2;
        INDArray x = Nd4j.linspace(1, len, len).reshape('c', 2, 4, 4, 2);
        DynamicCustomOp op = DynamicCustomOp.builder("maxpool2d").addIntegerArguments(new int[] { 2, 2, 2, 2, 0, 0, 1, 1, 0, 1, 1 }).addInputs(x).addOutputs(Nd4j.create(new int[] { 2, 2, 2, 2 }, outputOrder)).build();
        Nd4j.getExecutioner().exec(op);
        INDArray out = op.getOutputArgument(0);
        assertEquals("Output order: " + outputOrder, exp, out);
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DynamicCustomOp(org.nd4j.linalg.api.ops.DynamicCustomOp) NDArrayIndex.point(org.nd4j.linalg.indexing.NDArrayIndex.point) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 10 with DynamicCustomOp

use of org.nd4j.linalg.api.ops.DynamicCustomOp in project nd4j by deeplearning4j.

the class ConvolutionTests method testPooling12.

@Test
public void testPooling12() {
    for (char outputOrder : new char[] { 'c', 'f' }) {
        INDArray exp = Nd4j.create(new float[] { 3.f, 4.f, 4.5f, 6.f, 7.f, 7.5f, 7.5f, 8.5f, 9.f }, new int[] { 1, 1, 3, 3 }, 'c');
        int len = 1 * 1 * 3 * 3;
        INDArray x = Nd4j.linspace(1, len, len).reshape('c', 1, 1, 3, 3);
        DynamicCustomOp op = DynamicCustomOp.builder("avgpool2d").addIntegerArguments(new int[] { 2, 2, 1, 1, 0, 0, 1, 1, 1, 0, 0 }).addInputs(x).addOutputs(Nd4j.create(new int[] { 1, 1, 3, 3 }, outputOrder)).build();
        Nd4j.getExecutioner().exec(op);
        INDArray out = op.getOutputArgument(0);
        assertEquals("Output order: " + outputOrder, exp, out);
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DynamicCustomOp(org.nd4j.linalg.api.ops.DynamicCustomOp) NDArrayIndex.point(org.nd4j.linalg.indexing.NDArrayIndex.point) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Aggregations

Test (org.junit.Test)26 INDArray (org.nd4j.linalg.api.ndarray.INDArray)26 DynamicCustomOp (org.nd4j.linalg.api.ops.DynamicCustomOp)26 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)15 NDArrayIndex.point (org.nd4j.linalg.indexing.NDArrayIndex.point)14 SDVariable (org.nd4j.autodiff.samediff.SDVariable)10 SameDiff (org.nd4j.autodiff.samediff.SameDiff)10 ArrayList (java.util.ArrayList)2 DifferentialFunction (org.nd4j.autodiff.functions.DifferentialFunction)2 Ignore (org.junit.Ignore)1 MMulTranspose (org.nd4j.linalg.api.blas.params.MMulTranspose)1 Mmul (org.nd4j.linalg.api.ops.impl.accum.Mmul)1 TruncateDivOp (org.nd4j.linalg.api.ops.impl.transforms.arithmetic.TruncateDivOp)1 GreaterThanOrEqual (org.nd4j.linalg.api.ops.impl.transforms.comparison.GreaterThanOrEqual)1 LessThanOrEqual (org.nd4j.linalg.api.ops.impl.transforms.comparison.LessThanOrEqual)1 OldMax (org.nd4j.linalg.api.ops.impl.transforms.comparison.OldMax)1 OldMin (org.nd4j.linalg.api.ops.impl.transforms.comparison.OldMin)1 BernoulliDistribution (org.nd4j.linalg.api.ops.random.impl.BernoulliDistribution)1 Pair (org.nd4j.linalg.primitives.Pair)1