alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ReshapePreProcessorTest.java)

This example Java source code file (ReshapePreProcessorTest.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

indarray, reshapepreprocessor, reshapepreprocessortest, test

The ReshapePreProcessorTest.java Java example source code

package org.deeplearning4j.nn.conf.preprocessor;

import static org.junit.Assert.*;

import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.junit.Test;

/**
 * Created by merlin on 7/31/15.
 */
public class ReshapePreProcessorTest {

        private static int rows = 28;
        private static int cols = 28;
        INDArray in2D = Nd4j.create(1, 784);
        INDArray in3D = Nd4j.create(1, 784, 7);
        INDArray in4D = Nd4j.create(20, 1, 28, 28);


        @Test
        public void testPreProcessor2to4() {
                ReshapePreProcessor processor = new ReshapePreProcessor(new int[]{1, 784}, new int[]{1, 1, 28, 28});

                INDArray check2to4 = processor.preProcess(in2D,-1);
                int val2to4 = check2to4.shape().length;
                assertTrue(val2to4 == 4);
        }
        @Test
        public void testPreProcessor4to2() {
                ReshapePreProcessor processor = new ReshapePreProcessor(new int[] {20, 1, 28, 28}, new int[]{20, 784});
                INDArray result2 = processor.preProcess(in4D,-1);
                int val4to4 = result2.shape().length;
                assertTrue(val4to4 == 2);
        }


        @Test
        public void testPreProcessorBackprop2to4() {
                ReshapePreProcessor processor = new ReshapePreProcessor(new int[]{1, 784}, new int[]{1, 1, 28, 28});

                INDArray check2to2 = processor.backprop(in2D,-1);
                int val2to2 = check2to2.shape().length;
                assertTrue(val2to2 == 2);
        }

        @Test
        public void testPreProcessorBackprop3to2() {
                ReshapePreProcessor processor = new ReshapePreProcessor(new int[]{1, 784, 7}, new int[] {1, 5488});

                INDArray check3to2 = processor.backprop(in3D,-1);
                int val3to2 = check3to2.shape().length;
                assertTrue(val3to2 == 3);

        }



}

Other Java examples (source code examples)

Here is a short list of links related to this Java ReshapePreProcessorTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.