Quick Start Guide
This is everything you need to run DL4J examples and begin your own projects.
We recommend that you join our Gitter Live Chat. Gitter is where you can request help and give feedback, but please do use this guide before asking questions we’ve answered below. If you are new to deep learning, we’ve included a road map for beginners with links to courses, readings and other resources.
A Taste of Code
Deeplearning4j is a domain-specific language to configure deep neural networks, which are made of multiple layers. Everything starts with a
MultiLayerConfiguration, which organizes those layers and their hyperparameters.
Hyperparameters are variables that determine how a neural network learns. They include how many times to update the weights of the model, how to initialize those weights, which activation function to attach to the nodes, which optimization algorithm to use, and how fast the model should learn. This is what one configuration would look like:
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .iterations(1) .weightInit(WeightInit.XAVIER) .activation("relu") .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .learningRate(0.05) // ... other hyperparameters .backprop(true) .build();
With Deeplearning4j, you add a layer by calling
layer on the
NeuralNetConfiguration.Builder(), specifying its place in the order of layers (the zero-indexed layer below is the input layer), the number of input and output nodes,
nOut, as well as the type:
.layer(0, new DenseLayer.Builder().nIn(784).nOut(250) .build())
Once you’ve configured your net, you train the model with
- Java (developer version) 1.7 or later (Only 64-Bit versions supported)
- Apache Maven (automated build and dependency manager)
- IntelliJ IDEA or Eclipse
You should have these installed to use this QuickStart guide. DL4J targets professional Java developers who are familiar with production deployments, IDEs and automated build tools. Working with DL4J will be easiest if you already have experience with these.
If you are new to Java or unfamiliar with these tools, read the details below for help with installation and setup. Otherwise, skip to DL4J Examples.
If you don’t have Java 1.7 or later, download the current Java Development Kit (JDK) here. To check if you have a compatible version of Java installed, use the following command:
Please make sure you have a 64-Bit version of java installed, as you will see an error telling you
no jnind4j in java.library.path if you decide to try to use a 32-Bit version instead.
Maven is a dependency management and automated build tool for Java projects. It works well with IDEs such as IntelliJ and lets you install DL4J project libraries easily. Install or update Maven to the latest release following their instructions for your system. To check if you have the most recent version of Maven installed, enter the following:
If you are working on a Mac, you can simply enter the following into the command line:
brew install maven
Maven is widely used among Java developers and it’s pretty much mandatory for working with DL4J. If you come from a different background and Maven is new to you, check out Apache’s Maven overview and our introduction to Maven for non-Java programmers, which includes some additional troubleshooting tips. Other build tools such as Ivy and Gradle can also work, but we support Maven best.
An Integrated Development Environment (IDE) allows you to work with our API and configure neural networks in a few steps. We strongly recommend using IntelliJ, which communicates with Maven to handle dependencies. The community edition of IntelliJ is free.
Install the latest version of Git. If you already have Git, you can update to the latest version using Git itself:
$ git clone git://git.kernel.org/pub/scm/git/git.git
Use command line to enter the following:
$ git clone https://github.com/deeplearning4j/dl4j-examples.git $ cd dl4j-examples/ $ mvn clean install
Open IntelliJ and choose Import Project. Then select the main ‘dl4j-examples’ directory. (Note that it is dl4j-0.4-examples on pictures, that is an outdated repository name, you should use dl4j-examples everywhere).
Choose ‘Import project from external model’ and ensure that Maven is selected.
Continue through the wizard’s options. Select the SDK that begins with
jdk. (You may need to click on a plus sign to see your options…) Then click Finish. Wait a moment for IntelliJ to download all the dependencies. You’ll see the horizontal bar working on the lower right.
Pick an example from the file tree on the left. Right-click the file to run.
Using DL4J In Your Own Projects: Configuring the POM.xml File
To run DL4J in your own projects, we highly recommend using Maven for Java users, or a tool such as SBT for Scala. The basic set of dependencies and their versions are shown below. This includes:
deeplearning4j-core, which contains the neural network implementations
nd4j-native-platform, the CPU version of the ND4J library that powers DL4J
datavec-api- Datavec is our library vectorizing and loading data
Every Maven project has a POM file. Here is how the POM file should appear when you run your examples.
Within IntelliJ, you will need to choose the first Deeplearning4j example you’re going to run. We suggest
MLPClassifierLinear, as you will almost immediately see the network classify two groups of data in our UI. The file on Github can be found here.
To run the example, right click on it and select the green button in the drop-down menu. You will see, in IntelliJ’s bottom window, a series of scores. The rightmost number is the error score for the network’s classifications. If your network is learning, then that number will decrease over time with each batch it processes. At the end, this window will tell you how accurate your neural-network model has become:
In another window, a graph will appear, showing you how the multilayer perceptron (MLP) has classified the data in the example. It will look like this:
Congratulations! You just trained your first neural network with Deeplearning4j. Now, why don’t you try our next tutorial: MNIST for Beginners, where you’ll learn how to classify images.
- Join us on Gitter. We have three big community channels.
- DL4J Live Chat is the main channel for all things DL4J. Most people hang out here.
- Tuning Help is for people just getting started with neural networks. Beginners please visit us here!
- Early Adopters is for those who are helping us vet and improve the next release. WARNING: This is for more experienced folks.
- Read the introduction to deep neural networks or one of our detailed tutorials.
- Check out the more detailed Comprehensive Setup Guide.
- Browse the DL4J documentation.
- Deeplearning4j artifacts on Maven Central
- ND4J artifacts on Maven Central
- Datavec artifacts on Maven Central
Q: I’m using a 64-Bit Java on Windows and still get the
no jnind4j in java.library.path error
A: You may have incompatible DLLs on your PATH. To tell DL4J to ignore those, you have to add the following as a VM parameter (Run -> Edit Configurations -> VM Options in IntelliJ):