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

Java example source code file (ActivationMeanIterationListener.java)

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

activationmeaniterationlistener, awt, bufferedimage, file, image, imageio, indarray, ioexception, layer, override

The ActivationMeanIterationListener.java Java example source code

package org.deeplearning4j.plot.iterationlistener;

import org.canova.image.loader.ImageLoader;
import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.api.Model;
import org.deeplearning4j.optimize.api.IterationListener;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.ops.transforms.Transforms;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author Adam Gibson
 */
public class ActivationMeanIterationListener implements IterationListener {
    private int iteration = 1;
    private File outputFile = new File("activations.png");


    public ActivationMeanIterationListener(int iteration) {
        this.iteration = iteration;
    }

    public int getIteration() {
        return iteration;
    }

    public void setIteration(int iteration) {
        this.iteration = iteration;
    }


    public File getOutputFile() {
        return outputFile;
    }

    public void setOutputFile(File outputFile) {
        this.outputFile = outputFile;
    }

    @Override
    public boolean invoked() {
        return false;
    }

    @Override
    public void invoke() {

    }

    @Override
    public void iterationDone(Model model, int iteration) {
        if(iteration % this.iteration == 0) {
            Layer l = (Layer) model;
            INDArray activationMean = l.activate();
            INDArray weights = Transforms.sigmoid(activationMean);


            BufferedImage image = ImageLoader.toImage(weights);
            try {
                ImageIO.write(image, "png", outputFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Other Java examples (source code examples)

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