We need to add DL4J/ND4J Maven dependencies to leverage DL4J capabilities. ND4J is a scientific computation library dedicated to DL4J. It is necessary to mention the ND4J backend dependency in your pom.xml file. In this recipe, we will add a CPU-specific Maven configuration in pom.xml.
Configuring Maven for DL4J
Getting ready
Let's discuss the required Maven dependencies. We assume you have already done the following:
- JDK 1.7, or higher, is installed and the PATH variable is set.
- Maven is installed and the PATH variable is set.
Set the PATH variable for JDK and Maven:
- On Linux: Use the export command to add Maven and JDK to the PATH variable:
export PATH=/opt/apache-maven-3.x.x/bin:$PATH
export PATH=${PATH}:/usr/java/jdk1.x.x/bin
Replace the version number as per the installation.
- On Windows: Set System Environment variables from system Properties:
set PATH="C:/Program Files/Apache Software Foundation/apache-maven-3.x.x/bin:%PATH%"
set PATH="C:/Program Files/Java/jdk1.x.x/bin:%PATH%"
Replace the JDK version number as per the installation.
How to do it...
- Add the DL4J core dependency:
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>1.0.0-beta3</version>
</dependency>
- Add the ND4J native dependency:
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>1.0.0-beta3</version>
</dependency>
- Add the DataVec dependency to perform ETL (short for Extract, Transform and Load) operations:
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>1.0.0-beta3</version>
</dependency>
- Enable logging for debugging:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version> //change to latest version
</dependency>
How it works...
After adding DL4J core dependency and ND4J dependencies, as mentioned in step 1 and step 2, we are able to create neural networks. In step 2, the ND4J maven configuration is mentioned as a necessary backend dependency for Deeplearnign4j. ND4J is the scientific computation library for Deeplearning4j.
ND4J is a scientific computing library written for Java, just like NumPy is for Python.
Step 3 is very crucial for the ETL process: that is, data extraction, transformation, and loading. So, we definitely need this as well in order to train the neural network using data.
Step 4 is optional but recommended, since logging will reducee the effort involved in debugging.