src/main/java/convnet/CNN.java
/**
     * Logic for a full convolution operation.
     *
     * @param input
     * @param kernel
     * @param bias
     * @return
     */
Logic for a full convolution operation.
Logic for a full convolution operation .
private Data evalFullConvolution(Data input, Data kernel, double bias) {
        int m = input.getDimensions()[0];
        int n = input.getDimensions()[1];
        int o = input.getDimensions()[2];
        int km = kernel.getDimensions()[0];
        int kn = kernel.getDimensions()[1];
        int ko = kernel.getDimensions()[2];
        if (o != ko) {
            throw new RuntimeException("Malformed kernel and input. Different depths.");
        }
        double[][][] input3d = input.read3d();
        double[][][] fullInput = new double[m + 2 * (km - 1)][n + 2 * (kn - 1)][o];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < o; k++) {
                    fullInput[i + km - 1][j + kn - 1][k] = input3d[i][j][k];
                }
            }
        }
        Data fullInputData = new Data();
        fullInputData.write(fullInput);
        return evalValidConvolution(fullInputData, kernel, bias);
    }
private Data evalFullConvolution ( Data input , Data kernel , double bias ) { int m = input . getDimensions ( ) [ 0 ] ; int n = input . getDimensions ( ) [ 1 ] ; int o = input . getDimensions ( ) [ 2 ] ; int km = kernel . getDimensions ( ) [ 0 ] ; int kn = kernel . getDimensions ( ) [ 1 ] ; int ko = kernel . getDimensions ( ) [ 2 ] ; if ( o != ko ) { throw new RuntimeException ( "Malformed kernel and input. Different depths." ) ; } double [ ] [ ] [ ] input3d = input . read3d ( ) ; double [ ] [ ] [ ] fullInput = new double [ m + 2 * ( km - 1 ) ] [ n + 2 * ( kn - 1 ) ] [ o ] ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < o ; k ++ ) { fullInput [ i + km - 1 ] [ j + kn - 1 ] [ k ] = input3d [ i ] [ j ] [ k ] ; } } } Data fullInputData = new Data ( ) ; fullInputData . write ( fullInput ) ; return evalValidConvolution ( fullInputData , kernel , bias ) ; }
Logic for a full convolution operation.
Logic for a full convolution operation .