src/main/java/convnet/CNN.java
/**
     * Logic for a max pooling operation on a tensor.
     * @param input
     * @return
     */
Logic for a max pooling operation on a tensor.
@param input
@return
Logic for a max pooling operation on a tensor . @param input @return
private Data evalMaxPooling(Data input, int size, int stride) {
        int m = input.getDimensions()[0];
        int n = input.getDimensions()[1];
        int o = input.getDimensions()[2];
        int rm = ((m - size) / stride) + 1;
        int rn = ((n - size) / stride) + 1;
        double[][][] result = new double[rm][rn][o];
        for (int i = 0; i < rm; i = i + stride) {
            for (int j = 0; j < rn; j = j + stride) {
                for (int k = 0; k < o; k++) {
                    int si = i / stride;
                    int sj = j / stride;
                    List<Double> pool = new ArrayList<>();
                    for (int l = 0; l < size; l++) {
                        for (int p = 0; p < size; p++) {
                            pool.add(input.read3d()[i + l][j + p][k]);
                        }
                    }
                    result[si][sj][k] =  Collections.max(pool);
                }
            }
        }
        Data output = new Data();
        output.write(result);
        return output;
    }
private Data evalMaxPooling ( Data input , int size , int stride ) { int m = input . getDimensions ( ) [ 0 ] ; int n = input . getDimensions ( ) [ 1 ] ; int o = input . getDimensions ( ) [ 2 ] ; int rm = ( ( m - size ) / stride ) + 1 ; int rn = ( ( n - size ) / stride ) + 1 ; double [ ] [ ] [ ] result = new double [ rm ] [ rn ] [ o ] ; for ( int i = 0 ; i < rm ; i = i + stride ) { for ( int j = 0 ; j < rn ; j = j + stride ) { for ( int k = 0 ; k < o ; k ++ ) { int si = i / stride ; int sj = j / stride ; List < Double > pool = new ArrayList < > ( ) ; for ( int l = 0 ; l < size ; l ++ ) { for ( int p = 0 ; p < size ; p ++ ) { pool . add ( input . read3d ( ) [ i + l ] [ j + p ] [ k ] ) ; } } result [ si ] [ sj ] [ k ] = Collections . max ( pool ) ; } } } Data output = new Data ( ) ; output . write ( result ) ; return output ; }
Logic for a max pooling operation on a tensor.
Logic for a max pooling operation on a tensor .