Saturday, November 11, 2017

How to use DL4J for Windows

I am using Windows8.1 for my OS. The official quick start guide is here.
Suppose we are using Windows 8.1.

JDK


At first, we will install JDK. Make sure you will install (or have installed already?) Java8. As of November 2017, DL4J doesn't work under Java9.
Install from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


Then set the path for Java home. Open the control panel and choose the "System and Security" --> "System".
Click the Advanced tab and the button Environment Variables.



Click New... at the System Variables or User variables.
Use JDK_HOME as the variable name and "C:\Program Files\Java\(your jdk folder)" as the path.

If you have installed wrong version of Java (like java9) and want to change the version, download the right version of Java and change the path of JAVA_HOME to the new JDK's path. If this doesn't work and if you are using windows8, check if there is "C:\ProgramData\Oracle\Java\javapath" in the "Path" in System Variables. If there is, delete "C:\ProgramData\Oracle\Java\javapath" from the path. Otherwise the Java version doesn't change on the command prompt.

Check if JDK is installed successfully by running a command "java -version" on command prompt.
java -version

java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Maven


Then install Maven.
Visit the official site of Maven: http://maven.apache.org/download.cgi
And install Maven (like "apache-maven-3.5.2-bin.zip") from there.

After the installation, add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder.


Maven is a project management tool, which is aimed for Java projects.
Available commands of Maven:
install
clean
compile
package
validate
test-compile
test
integration-test
verify
deploy

Check if Mave is installed successfully by running the following command.
mvn -version

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T16:58:1
3+09:00)
Maven home: C:\Program Files\Apache\maven\bin\..
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1_8\jre
Default locale: en_GB, platform encoding: MS932
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
'cmd' is not recognized as an internal or external command,
operable program or batch file.

Git


Download the latest Git for Windows installer from here: https://git-for-windows.github.io/
Then install git with the installer.

After the installation, check if the git works correctly on the command prompt.
git --version

git version 2.7.4


Install DL4J


Create a workplace folder and name it as "dl4j".

Then move to the directory on the command prompt.
cd C:\Users\Jack\Documents\dl4j

Install dl4j from git.
git clone https://github.com/deeplearning4j/dl4j-examples.git
cd dl4j-examples/
mvn clean install

Intellij


Install free community version of Intellij from here: https://www.jetbrains.com/idea/download/#section=windows

Open intellij and choose "import project".


Choose the folder of dl4j-examples which we downloaded just now and click "OK".


Choose "Maven" and click "Next".


Just click "Next" without touching anything.

Tick "open jfx" and click "Next".


Tick the URL of dl4j and click "Next".



Tick the SDK and click "Next".


Click "Finish".


Wait until the loading is finished.


Choose an example which you want to run and click on it to open the source. Then right-click on the class name. A menu will be shown. Click "Run" from the menu. Then the deep learning will be started.

I will try LenetMnistExample:

The result of LenetMnistExample:
==========================Scores========================================
 # of classes:    10
 Accuracy:        0.9746
 Precision:       0.9748
 Recall:          0.9745
 F1 Score:        0.9744
Precision, recall & F1: macro-averaged (equally weighted avg. of 10 classes)
========================================================================
o.d.e.c.LenetMnistExample - ****************Example finished********************