For a long time, Java has been the dominant software development platform rivalled by very few languages. But Java and its popularity had very little to do with the development of Machine Learning applications.
Though Java is faster than Python, it couldn’t make headway into the Artificial Intelligence(AI) and Machine Learning(ML) space dominated by Python and other languages that were much simpler and came packed with libraries for all kinds of ML tasks.
The rise of ML and AI applications and its huge demand has made Java more adaptable for related tasks by coming up with libraries and frameworks. Deeplearning4j is one such library that facilitates Java developers or programmers to create ML applications and to solve any ML related problem.
In this article, we will learn to get started with Deeplearning4j by setting up a development environment for building Machine Learning applications or projects in Java.
Install java for you OS
For instructions on how to install follow the link here
Setting Up Environment For Deeplearning4j
We will cover the entire set-up in 4 simple steps.
If you have worked with Java projects then you must be familiar with Apache Maven. A project management and comprehension tool that lets you build applications from a POM(Project Object Model) file. We will start by downloading and installing the latest Apache Maven. Follow the steps below:
Step 1. Verify if Java is installed correctly by typing
java -- version in your terminal. If installed correctly, the command will return the version of the java installed. If not try setting the path environment to the installed location of Java.
Execute the following command to add the JAVA_HOME environment variable. The following examples have been made in OSx.
Check for the location of the Home directory in your installed java location.
This command only adds the path for the current session, to persist the changes type
emacs .profile on your Mac terminal and add the following line to the file and save it.
Execute the following code to add the java bin path
Follow the instructions here for Windows or Linux systems.
Step 2. Head to https://maven.apache.org/download.cgi and download the archive for the latest maven source code.
Step 3. Once downloaded, extract the archive using any decompressing utility and move the decompressed folder to the user directory.
mv apache-maven-3.6.1 /Users/user/
Step 4. Set the path environment variable to include maven and test if maven is installed correctly.
To set the path, execute the following command:
To verify, execute
Step 1. Head to https://git-scm.com/download/ which is the downloads page on Github’s official website. Select the installer for your operating system and it will be downloaded to your system.
The installation process is pretty straight forward. Run the installer to install Github in your system.
Step 2. Verify the installation by executing the
git --version in your terminal or command prompt.
You should get a similar output if everything is right.
Installing Intellij IDE
Step 1. Head to the official download page of Intellij by clicking here. Choose the installer for your os and click the download should start. We will stick to the free community edition.
Step 2. Once downloaded execute the installer to install Intellij IDE in your system.
Building and running an example project with Deeplearning4j
Step 1. Head to https://deeplearning4j.org/ and click on the examples section which will take you to the official Github repository for Deeplearning4j examples.
Step 2. Clone the repository to your local system
Copy the cloning url and execute the below command with the copied url. Make a local directory to clone the repository.
git clone https://github.com/deeplearning4j/dl4j-examples.git
Step 3. After cloning move inside to the dl4j-examples/dl4j-examples directory and execute the command
mvn clean install to build the project. It may take some time to build the project.
Step 4. Once finished building, open Intellij IDE and select import project since we already have an example project that we built using maven.
On the upcoming page, select maven to specify that the project is a maven build. Include the checkbox to import maven projects automatically in the next page and next and import.
Step 5. Set the location of the project that we built using maven, select the libraries you want to include and click open to import the project into Intellij. The IDE will open up with your project imported. Wait till the processes are completed and once done you will find the project on the projects bar on the left side.
Step 6. Expand the projects and head to src/main/java/org.deeplearning4j.examples/dataexamples. You will find a hand full of examples.
Double click on an example to open up the code. Execute the code by clicking on the run button and enjoy the results.
Step 7. You can now create or import new Maven projects using IntelliJ.
Congrats! You have set up a free java environment for Machine Learning. Happy Coding !!
Register for our upcoming events:
- Join the Grand Finale of Intel Python HackFury2: 21st Oct, Bangalore
- WEBINAR: HOW TO BEGIN A CAREER IN DATA SCIENCE | 24th Oct
- Machine Learning Developers Summit 2020: 22-23rd Jan, Bangalore | 30-31st Jan, Hyderabad
Enjoyed this story? Join our Telegram group. And be part of an engaging community.
Provide your comments below
What's Your Reaction?
A Computer Science Engineer who is passionate about AI and all related technologies. He is someone who loves to stay updated with the Tech-revolutions that AI brings in. Contact: email@example.com