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

Java example source code file (KernelValidationUtil.java)

This example Java source code file (KernelValidationUtil.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

invalid, invalidinputtypeexception, kernelvalidationutil

The KernelValidationUtil.java Java example source code

package org.deeplearning4j.nn.layers.convolution;

import org.deeplearning4j.nn.conf.inputs.InvalidInputTypeException;


/**
 * Confirm calculations to reduce the shape of the input based on convolution or subsampling transformation
 */
public class KernelValidationUtil {

    public static void validateShapes(int inHeight, int inWidth, int kernelHeight, int kernelWidth, int strideHeight,
                               int strideWidth, int padHeight, int padWidth) {

        // Check filter > size + padding
        if (kernelHeight > (inHeight + 2*padHeight))
            throw new InvalidInputTypeException("Invalid input: activations into layer are h=" + inHeight
                    + " but kernel size is " + kernelHeight + " with padding " + padHeight);

        if (kernelWidth > (inWidth + 2*padWidth))
            throw new InvalidInputTypeException("Invalid input: activations into layer are w=" + inWidth +
                    " but kernel size is " + kernelWidth + " with padding " + padWidth);

        // Check stride
        if ((strideHeight <= 0) || (strideWidth <= 0))
            throw new InvalidInputTypeException("Invalid stride: strideHeight is " + strideHeight
                    + " and strideWidth is " + strideWidth + " and both should be great than 0");

        // Below is to confirm an integer comes out of the calculation but this is taken care of in nd4j
        //Check proposed filter/padding size actually works:
//        if ((inHeight - kernelHeight + 2 * padHeight) % strideHeight != 0) {
//            throw new InvalidInputTypeException("Invalid input/configuration: activations into layer are inputHeight=" + inHeight + ", heightPadding=" + padHeight
//                    + ", kernelHeight = " + kernelHeight + ", strideHeight = " + strideHeight + ". (inputHeight-kernelHeight+2*heightPadding)/strideHeight is not an integer");
//        }
//        if ((inWidth - kernelWidth + 2 * padWidth) % strideWidth != 0)
//            throw new InvalidInputTypeException("Invalid input/configuration: activations into layer are inputWidth=" + inWidth + ", widthPadding=" + padWidth
//                    + ", kernelWidth = " + kernelWidth + ", strideWidth = " + strideWidth + ". (inputWidth-kernelWidth+2*widthPadding)/strideWidth is not an integer");

    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java KernelValidationUtil.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.