Deep Learning in Java – Getting Started With Deep Netts

This is a step by step guide for downloading, installing, and running a minimal example.

  1. Requirements
  2. Download
  3. Installation
  4. Running first deep learning example (Hello world!)

1. Requirements

Java 8 or higher
Deep Netts requires Java version 8 or higher installed.
Java is available for download at https://www.oracle.com/java/technologies/javase-downloads.html

Apache Maven Build Tool
Maven build tool is the easiest and recommended way to use Deep Netts.
Maven is available for download for free from https://maven.apache.org/download.cgi
Maven installation is just unpacking the downloaded archive and setting environment variables
For more details depending on OS see https://maven.apache.org/install.html

2. Download

Deep Netts is available for free download from here
The download package includes both the Deep Learning IDE and Java library.

3. Installation

3.1. Deep Learning IDE Installation

Deep Learning IDE installation is performed by unzipping the provided application zip file:

  1. Unzip downloaded package deepnetts.zip
  2. Unzip deepnettsplatform.zip provided in the distribution package (deepnetts/deepnettsplatform.zip)
  3. Start Deep Netts by running

deepnettsplatform/bin/deepnettsplatform64.exe for Windows or
deepnettsplatform/bin/deepnettsplatform64.sh for Mac or Linux. For Linux make sure that the file has executable permissions.
Or make sure that it does run and the following command: chmod +x deepnettsplatform64.sh

3.2. Local Maven installation of Deep Netts library

To be able to use Deep Netts in your Maven-based Java applications install provided jar files (including license jar) into your local Maven repository. You can do that using scripts provided in the distribution package:

ImportToLocalMaven.bat             for Windows
importToLocalMaven.sh               for Linux and Mac

If everything went well, after running the import scripts you should be able to find Deep Netts library and license in  .m2/com/deepnetts directory. Location of your local Maven repository is commonly  {USER_DIR}/.m2
Where {USER_DIR} is your user home directory c:\Users\Username on Win or /home/username on Linux

3.3. Adding dependencies to Deep Netts library in your Java project

Maven Based Java project

To add Deep Netts to your Maven based Java project, copy and paste the following snippets to <dependencies> section in pom.xml file of your project.

        <dependency>
            <groupId>com.deepnetts</groupId>
            <artifactId>deepnetts-core-pro</artifactId>
            <version>x.x</version>
        </dependency>

        <dependency>
            <groupId>com.deepnetts</groupId>
            <artifactId>deepnetts-license</artifactId>
            <version>1.0</version>
        </dependency>

This will add Deep Netts library and license file to your project and all related dependencies.

ANT Based Java Project

To add Deep Netts to your ANT based project, add all jar files provided in DeepNettsEngine directory from downloaded  Deep Netts distribution to your project.

4. Running first deep learning example (hello world)

Iris Flowers Classification – A Multi Class Classification task. Assign flower to one of three categories based on their dimensions. You can run this example from your favourite IDE using maven project at Examples/deepnetts-examples or from th command line using following commands:

cd Examples/deepnetts-examples
mvn clean package
mvn exec:java -Dexec.mainClass=deepnetts.examples.IrisFlowersClassification

public class IrisFlowersClassification {

    private static final Logger LOGGER = LogManager.getLogger(DeepNetts.class.getName());

    public static void main(String[] args) throws DeepNettsException, IOException {
        // load iris data  set
        DataSet dataSet = DataSets.readCsv("datasets/iris-flowers.csv", 4, 3, true, ",");
        TrainTestPair trainTest = DataSets.trainTestSplit(dataSet, 0.65);

        // normalize data using max normalization
        MaxNormalizer norm = new MaxNormalizer(trainTest.getTrainingeSet());
        norm.normalize(trainTest.getTrainingeSet());   
        norm.normalize(trainTest.getTestSet());
        
        // create instance of feed forward neural network using builder
        FeedForwardNetwork neuralNet = FeedForwardNetwork.builder()
                .addInputLayer(4)
                .addFullyConnectedLayer(8, ActivationType.TANH)
                .addOutputLayer(3, ActivationType.SOFTMAX)
                .lossFunction(LossType.CROSS_ENTROPY)
                .randomSeed(123).
                build();
        
        // create and configure instanceof backpropagation trainer
        BackpropagationTrainer trainer = neuralNet.getTrainer();
        trainer.setMaxError(0.03f)
               .setMaxEpochs(1000000)
               .setLearningRate(0.1f);
                                 
        trainer.train(trainTest.getTrainingeSet());

        ClassifierEvaluationResult ceResult = Evaluators.evaluateClassifier(neuralNet, trainTest.getTestSet());
        
        LOGGER.info("Classification performance measure" + System.lineSeparator());
        LOGGER.info(ceResult);
        
        // shutdown the thread pool
        DeepNetts.shutdown();            
    }

}

Next Steps

Scroll to Top