@Test public void testConvolutionalWithPaddingBackPropagate() { final Matrix error = convolutionalWithPaddingLayer.backPropagate( input, expectedConvolutionalWithPaddingActivation, nextErrorWithPadding); assertTrue(expectedConvolutionalWithPaddingError.compare(error, TOLERANCE)); }
@Override public Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError) { final Matrix error = matrixFactory.create(input.getRows(), input.getColumns()); for (int n = 0; n < input.getColumns(); ++n) { final Matrix singleNextError = nextError.getColumn(n).reshape(outputShape[1] * outputShape[2], outputShape[0]); final Matrix row = singleNextError.mmul(getLayerParameter().getWeightParam().transpose()); final Matrix im = row2im(row); error.putColumn(n, im); } return error; }
ConvolutionalLayer extends LayerBase { @Override public Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError) { final Matrix error = matrixFactory.create(input.getRows(), input.getColumns()); for (int n = 0; n < input.getColumns(); ++n) { final Matrix singleNextError = nextError.getColumn(n).reshape(outputShape[1] * outputShape[2], outputShape[0]); final Matrix row = singleNextError.mmul(getLayerParameter().getWeightParam().transpose()); final Matrix im = row2im(row); error.putColumn(n, im); } return error; } }
ConvolutionalLayer extends LayerBase { @Override public Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError) { final Matrix error = matrixFactory.create(input.getRows(), input.getColumns()); for (int n = 0; n < input.getColumns(); ++n) { final Matrix singleNextError = nextError.getColumn(n).reshape(outputShape[1] * outputShape[2], outputShape[0]); final Matrix row = singleNextError.mmul(getLayerParameter().getWeightParam().transpose()); final Matrix im = row2im(row); error.putColumn(n, im); } return error; } @Inject private  ConvolutionalLayer(@Parameter(LayerIndex.class) final int index,
                             @Parameter(LayerInputShape.class) final String inputShape,
                             @Parameter(PaddingHeight.class) final int paddingHeight,
                             @Parameter(PaddingWidth.class) final int paddingWidth,
                             @Parameter(StrideHeight.class) final int strideHeight,
                             @Parameter(StrideWidth.class) final int strideWidth,
                             @Parameter(KernelHeight.class) final int kernelHeight,
                             @Parameter(KernelWidth.class) final int kernelWidth,
                             final LayerParameterInitializer layerParameterInitializer,
                             final MatrixFactory matrixFactory); }
ConvolutionalLayer extends LayerBase { @Override public Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError) { final Matrix error = matrixFactory.create(input.getRows(), input.getColumns()); for (int n = 0; n < input.getColumns(); ++n) { final Matrix singleNextError = nextError.getColumn(n).reshape(outputShape[1] * outputShape[2], outputShape[0]); final Matrix row = singleNextError.mmul(getLayerParameter().getWeightParam().transpose()); final Matrix im = row2im(row); error.putColumn(n, im); } return error; } @Inject private  ConvolutionalLayer(@Parameter(LayerIndex.class) final int index,
                             @Parameter(LayerInputShape.class) final String inputShape,
                             @Parameter(PaddingHeight.class) final int paddingHeight,
                             @Parameter(PaddingWidth.class) final int paddingWidth,
                             @Parameter(StrideHeight.class) final int strideHeight,
                             @Parameter(StrideWidth.class) final int strideWidth,
                             @Parameter(KernelHeight.class) final int kernelHeight,
                             @Parameter(KernelWidth.class) final int kernelWidth,
                             final LayerParameterInitializer layerParameterInitializer,
                             final MatrixFactory matrixFactory); @Override int[] getOutputShape(); @Override boolean isLearnable(); @Override Matrix feedForward(final Matrix input); @Override Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError); @Override LayerParameter generateParameterGradient(final Matrix input, final Matrix error); }
ConvolutionalLayer extends LayerBase { @Override public Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError) { final Matrix error = matrixFactory.create(input.getRows(), input.getColumns()); for (int n = 0; n < input.getColumns(); ++n) { final Matrix singleNextError = nextError.getColumn(n).reshape(outputShape[1] * outputShape[2], outputShape[0]); final Matrix row = singleNextError.mmul(getLayerParameter().getWeightParam().transpose()); final Matrix im = row2im(row); error.putColumn(n, im); } return error; } @Inject private  ConvolutionalLayer(@Parameter(LayerIndex.class) final int index,
                             @Parameter(LayerInputShape.class) final String inputShape,
                             @Parameter(PaddingHeight.class) final int paddingHeight,
                             @Parameter(PaddingWidth.class) final int paddingWidth,
                             @Parameter(StrideHeight.class) final int strideHeight,
                             @Parameter(StrideWidth.class) final int strideWidth,
                             @Parameter(KernelHeight.class) final int kernelHeight,
                             @Parameter(KernelWidth.class) final int kernelWidth,
                             final LayerParameterInitializer layerParameterInitializer,
                             final MatrixFactory matrixFactory); @Override int[] getOutputShape(); @Override boolean isLearnable(); @Override Matrix feedForward(final Matrix input); @Override Matrix backPropagate(final Matrix input, final Matrix activation, final Matrix nextError); @Override LayerParameter generateParameterGradient(final Matrix input, final Matrix error);  }