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);
}
}
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:
*/
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations