UIServer not starting up (I think)

Hello there.

I am new to the deeplearning4j toolkit and have a real beginner question. I have downloaded some example code and have not changed it, except some printouts. I want to get the UI running, so that I can inspect the learning and the model under localhost:9000/train/overview

The code runs fine, and reaches the end without problems. I keep getting “The site can not be reached” when going to the above addres. I suspect that the http server is not starting, as when I instert the code
System.out.println("Port: "+uiServer.getPort());
I get an nullpointer exception from inside the uiServer.

Please help to get me started.

This is my code:

    package mygroupid.com.UITest;


    import java.io.File;

    import org.deeplearning4j.api.storage.StatsStorage;
    import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
    import org.deeplearning4j.ui.api.UIServer;
    import org.deeplearning4j.ui.stats.StatsListener;
    import org.deeplearning4j.ui.storage.FileStatsStorage;
    import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;

    /**
     * A simple example of how to attach Deeplearning4j's training UI to a network
     *
     * To change the UI port (usually not necessary) - set the org.deeplearning4j.ui.port system property
     * i.e., run the example and pass the following to the JVM, to use port 9001: -Dorg.deeplearning4j.ui.port=9001
     *
     * @author Alex Black
     */
    public class UIExample {

        public static void main(String[] args){
        	System.out.println("sddf");
            //Get our network and training data
            MultiLayerNetwork net = UIExampleUtils.getMnistNetwork();
            DataSetIterator trainData = UIExampleUtils.getMnistData();

            //Initialize the user interface backend
            UIServer uiServer = UIServer.getInstance();
            

            //Configure where the network information (gradients, activations, score vs. time etc) is to be stored
            //Then add the StatsListener to collect this information from the network, as it trains
            StatsStorage statsStorage = new FileStatsStorage(new File(System.getProperty("java.io.tmpdir"), "ui-stats.dl4j"));
            int listenerFrequency = 1;
            net.setListeners(new StatsListener(statsStorage, listenerFrequency));

            //Attach the StatsStorage instance to the UI: this allows the contents of the StatsStorage to be visualized
            uiServer.attach(statsStorage);
            

    //        System.out.println("Port: "+uiServer.getPort());
    //        System.out.println("Address: "+uiServer.getAddress());
    //        System.out.println("Running: "+uiServer.isStopped());

            //Start training:
            net.fit(trainData);

            System.out.println("done");
            //Finally: open your browser and go to http://localhost:9000/train
        }
    }
package mygroupid.com.UITest;
    import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
    import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
    import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
    import org.deeplearning4j.nn.conf.inputs.InputType;
    import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
    import org.deeplearning4j.nn.conf.layers.DenseLayer;
    import org.deeplearning4j.nn.conf.layers.OutputLayer;
    import org.deeplearning4j.nn.conf.layers.SubsamplingLayer;
    import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
    import org.deeplearning4j.nn.weights.WeightInit;
    import org.nd4j.linalg.activations.Activation;
    import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
    import org.nd4j.linalg.learning.config.Adam;
    import org.nd4j.linalg.lossfunctions.LossFunctions;

    import java.io.IOException;

    /**
     * Created by Alex on 11/11/2016.
     */
    public class UIExampleUtils {

        public static MultiLayerNetwork getMnistNetwork(){

            int nChannels = 1; // Number of input channels
            int outputNum = 10; // The number of possible outcomes
            int seed = 123; //

            MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
                .seed(seed)
                .l2(0.0005)
                .weightInit(WeightInit.XAVIER)
                .updater(new Adam(0.001))
                .list()
                .layer(new ConvolutionLayer.Builder(5, 5)
                    //nIn and nOut specify depth. nIn here is the nChannels and nOut is the number of filters to be applied
                    .nIn(nChannels)
                    .stride(1, 1)
                    .nOut(20)
                    .activation(Activation.LEAKYRELU)
                    .build())
                .layer(new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX)
                    .kernelSize(2,2)
                    .stride(2,2)
                    .build())
                .layer(new ConvolutionLayer.Builder(5, 5)
                    //Note that nIn need not be specified in later layers
                    .stride(1, 1)
                    .nOut(50)
                    .activation(Activation.LEAKYRELU)
                    .build())
                .layer(new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX)
                    .kernelSize(2,2)
                    .stride(2,2)
                    .build())
                .layer(new DenseLayer.Builder().activation(Activation.LEAKYRELU).nOut(500).build())
                .layer(new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
                    .nOut(outputNum)
                    .activation(Activation.SOFTMAX)
                    .build())
                .setInputType(InputType.convolutionalFlat(28,28,1))
                .build();


            MultiLayerNetwork net = new MultiLayerNetwork(conf);
            net.init();

            return net;
        }

        public static DataSetIterator getMnistData(){
            try{
                return new MnistDataSetIterator(64,true,12345);
            }catch (IOException e){
                throw new RuntimeException(e);
            }
        }

    }

And the pom:

  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <groupId>mygroupid.com</groupId>
   <artifactId>UITest</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>
 
   <name>UITest</name>
   <url>http://maven.apache.org</url>
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.deeplearning4j</groupId>
       <artifactId>deeplearning4j-core</artifactId>
       <version>1.0.0-beta6</version>
   	</dependency>
   	<dependency>
          <groupId>org.nd4j</groupId>
          <artifactId>nd4j-native-platform</artifactId>
          <version>1.0.0-beta6</version>
      </dependency>
      <dependency>
          <groupId>org.nd4j</groupId>
          <artifactId>nd4j-cuda-10.0-platform</artifactId>
          <version>1.0.0-beta6</version>
      </dependency>
      <dependency>
          <groupId>org.nd4j</groupId>
          <artifactId>nd4j-cuda-10.1-platform</artifactId>
          <version>1.0.0-beta6</version>
      </dependency>
      <dependency>
          <groupId>org.nd4j</groupId>
          <artifactId>nd4j-cuda-10.2-platform</artifactId>
          <version>1.0.0-beta6</version>
      </dependency>
      <dependency>
         <groupId>org.deeplearning4j</groupId>
         <artifactId>deeplearning4j-ui</artifactId>
         <version>1.0.0-beta6</version>
     </dependency>
     <dependency>
 	    <groupId>org.deeplearning4j</groupId>
 	    <artifactId>deeplearning4j-examples</artifactId>
 	    <version>0.0.3.1</version>
 	</dependency>
   </dependencies>
 </project>

You are using beta6, which had a known problem with the UI seemingly not starting due to dependency conflicts.

Update to beta7, and ideally use the official examples as a starting point: https://github.com/eclipse/deeplearning4j-examples

Thanks @treo.

When updating to beta7, I do however get a different error.
Caused by: java.lang.ClassNotFoundException: org.deeplearning4j.ui.storage.BaseCollectionStatsStorage$SessionTypeId

Apparently this class is missing, which is present in beta6. Any ideas on that problem?
I used maven -> update project with ‘Force update of snapshots’ enabled, so I should have all the new sources.

The code actually I posted above actually is from the official examples. I just have copied the code to my local project/package.

This is my pom now:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>mygroupid.com</groupId>
  <artifactId>UITest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>UITest</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.deeplearning4j</groupId>
      <artifactId>deeplearning4j-core</artifactId>
      <version>1.0.0-beta7</version>
  	</dependency>
  	<dependency>
         <groupId>org.nd4j</groupId>
         <artifactId>nd4j-native-platform</artifactId>
         <version>1.0.0-beta7</version>
     </dependency>
     <dependency>
         <groupId>org.nd4j</groupId>
         <artifactId>nd4j-cuda-10.0-platform</artifactId>
         <version>1.0.0-beta7</version>
     </dependency>
     <dependency>
         <groupId>org.nd4j</groupId>
         <artifactId>nd4j-cuda-10.1-platform</artifactId>
         <version>1.0.0-beta7</version>
     </dependency>
     <dependency>
         <groupId>org.nd4j</groupId>
         <artifactId>nd4j-cuda-10.2-platform</artifactId>
         <version>1.0.0-beta7</version>
     </dependency>
     <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-ui</artifactId>
        <version>1.0.0-beta7</version>
    </dependency>
    <dependency>
	    <groupId>org.deeplearning4j</groupId>
	    <artifactId>deeplearning4j-examples</artifactId>
	    <version>0.0.3.1</version>
	</dependency>
  </dependencies>
</project>

That looks very much like you have an unsupported mix of dependencies in your project.

In particular the dependency on deeplearning4j-examples.

If you need a template for a new maven project that uses DL4J, I suggest you start with the standalone sample project: https://github.com/eclipse/deeplearning4j-examples/tree/master/standalone-sample-project

Thanks again @treo.

I removed some dependencies, but could not get the above code to work.

I created a blank project and used the example code and pom you mentioned. I added the lines to get the UI running. That worked.

I do not know why my first attempt did not, but maybe I will find out at some later point, and then post the answer. Thanks for the help.