home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (UpdateActivationIterationListener.java)

This example Java source code file (UpdateActivationIterationListener.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, client, error, logger, override, pathupdate, runtimeexception, string, uiserver, updateactivationiterationlistener, util, webtarget

The UpdateActivationIterationListener.java Java example source code

package org.deeplearning4j.ui.activation;

import org.deeplearning4j.nn.api.Model;
import org.deeplearning4j.optimize.api.IterationListener;
import org.deeplearning4j.plot.iterationlistener.ActivationMeanIterationListener;
import org.deeplearning4j.ui.UiServer;
import org.deeplearning4j.ui.UiUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import java.util.List;

 * @author Adam Gibson
public class UpdateActivationIterationListener implements IterationListener {
    private static final Logger log = LoggerFactory.getLogger(UpdateActivationIterationListener.class);
    private Client client = ClientBuilder.newClient();
    private WebTarget target;
    private ActivationMeanIterationListener listener;
    private int iterations = 1;
    private boolean openBrowser;
    private boolean firstIteration = true;
    private String path;

     * Initializes with the variables to render filters for
     * @param iterations the number of iterations to update on
    public UpdateActivationIterationListener(int iterations) {

    public UpdateActivationIterationListener(int iterations, boolean openBrowser, String subPath){
        int port = -1;
            UiServer server = UiServer.getInstance();
            port = server.getPort();
        }catch(Exception e){
            log.error("Error initializing UI server",e);
            throw new RuntimeException(e);

        listener = new ActivationMeanIterationListener(iterations);
        this.iterations = iterations;
        this.openBrowser = openBrowser;
        path = "http://localhost:" + port + "/" + subPath;
        target = client.target("http://localhost:" + port).path(subPath).path("update");
        }catch(Exception e){
            log.error("Error initializing UI server",e);

    public boolean invoked() {
        return false;

    public void invoke() {


    public void iterationDone(Model model, int iteration) {
        if(iteration % iterations == 0) {
            PathUpdate update = new PathUpdate();
            //update the weights
            listener.iterationDone(model, iteration);
            //ensure path is set
            //ensure the server is hooked up with the path
            target.request(MediaType.APPLICATION_JSON).post(Entity.entity(update, MediaType.APPLICATION_JSON));
            if(openBrowser && firstIteration){
                UiUtils.tryOpenBrowser(path, log);
                firstIteration = false;


Other Java examples (source code examples)

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

my book on functional programming


new blog posts


Copyright 1998-2019 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.