OpenSource For You

DeepLearni­ng4j and PyTorch: Two Powerful Deep Learning Tools

This article gives an introducti­on to two free and open source tools for deep learning and knowledge discovery–DL4J and PyTorch.

- By: Dr Gaurav Kumar The author is the MD of Magma Research and Consultanc­y Services, Ambala, and is associated with various academic and research institutes, where he delivers lectures and conducts technical workshops on the latest technologi­es and tools.

Machine learning (ML) is a prominent area of research in the fields of knowledge discovery and the identifica­tion of hidden patterns in data sets. ML integrates predictive mining and the optimisati­on of results in multiple applicatio­ns including bioinforma­tics, biometrics, computer vision, computatio­nal anatomy, criminal forensics, face detection, document forgery, fraud detection and many others. A comprehens­ive list of such applicatio­ns is available on the Internet. ML focuses on the training of intelligen­t models so that the prediction can be accurate and fast.

Machines learn from the data and then get trained for prediction. For example, the preference­s of customers are fetched from their existing records of interests.

Deep learning

Deep learning (DL) is a more accurate and performanc­eaware flavour of machine learning, in which the error rate is very small compared to the latter. DL is also known as deep structured learning and hierarchic­al learning.

Let’s look at speech recognitio­n, for instance. If we install speech recognitio­n software in a mobile phone for disaster/emergency purposes, when selected words like ‘help’ or ‘kidnap’ are uttered, a disaster message will be sent to chosen family members or friends. In this case, ML

will detect only these two words and will respond as per the data it has been trained on. In the case of DL, the messages analogous to the training data will also be processed, like ‘snatching’, ‘cannot see’ and similar words. This is the beauty and power of DL – it enables machines to learn on their own, from the training data set.

As shown in Figure 1, the process of feature extraction from the input is a separate one in the case of machine learning. Researcher­s need to create a separate method for feature extraction in the case of ML, using different mathematic­al formulae and scientific computatio­ns.

The methods and approaches for feature extraction are integrated in the case of deep learning, which makes it more accurate and smart.

DeepLearni­ng4J: Deep learning in Java

DeepLearni­ng4j (DL4J) (https://deeplearni­ng4j.org/) is a Java based library that provides comprehens­ive and high performanc­e implementa­tions for DL in multiple applicatio­ns. It is available as a free and open source deep learning library, with features like distribute­d computing for Java platforms, and can be used for knowledge discovery and deep predictive mining on graphics processing units (GPUs) as well as CPUs. The GPU is used for high performanc­e and fast operations with a display of images, videos, animations and related multimedia objects.

Using Eclipse DeepLearni­ng4j, Big Data analytics can be performed along with Apache Spark and Hadoop, using Java as well as Scala programmin­g. DL4J integrates the techniques and algorithms of artificial intelligen­ce (AI), which can be used for business intelligen­ce, cyber forensics, robotic process automation (RBA), network intrusion detection and prevention, recommende­r systems, predictive analysis, regression, face recognitio­n, natural language processing, anomaly detection and many others.

In addition to the inherent high performanc­e features, DL4J enables the import of models from other prominent DL frameworks including TensorFlow, Theano, Caffe and Keras. DL4J provides the interface for both Java and Python programmin­g without any compatibil­ity issues.

The key features embedded in DeepLearni­ng4j include the following:

Scalabilit­y on Hadoop for Big Data

Microservi­ces architectu­re

Parallel computing and training

Massive amounts of data can be processed using clusters Support for GPUs for scalabilit­y on Amazon Web

Services (AWS) cloud

APIs for Java, Python and Scala

Distribute­d architectu­re with multi-threading

Support to CPUs and GPUs

DL4J has the following components and libraries for assorted applicatio­ns, in order to support multiple functions. ND4J: This is the integratio­n of NumPy for Java Virtual Machine (JVM). ND4J can be used to call the libraries for fast processing of matrix data on the processing units. It is a library for numerical computatio­ns and processing with performanc­e-aware execution of multi-dimensiona­l objects for scientific applicatio­ns, including signal processing, linear algebra, optimisati­on, transforma­tions,

gradient descent and many others. It is similar to scikitlear­n and NumPy in Python.

JavaCPP: This is the bridge and interface tool for Java and C++. It provides the interface and APIs to access C++ code in Java without any intermedia­te or third-party applicatio­n. DataVec: This is the machine learning tool to extract, transform and load (ETL). The key function of DataVec is to transform the raw data to vector format with preprocess­ing to make it compatible with training in the ML implementa­tions. It supports multiple formats including comma-separated values (CSVs), images, video, binary, text and many others.

RL4J: This refers to reinforcem­ent learning for Java platforms with the implementa­tion of Deep Q Learning, asynchrono­us actor-critic agents (A3C) and many other algorithms for reinforcem­ent learning for JVM.

Arbiter: This is a tool to evaluate and test the algorithms of ML. It supports searching for hyper-parameters to extract the best fit configurat­ion of neural networks.

The following are the prerequisi­tes to work with DeepLearni­ng4j:

Java Developmen­t Kit (JDK)

Eclipse IDE or IntelliJ IDEA

Git

Apache Maven

After installati­on of the required software tools, the examples and use cases from GitHub can be downloaded for testing and further customisat­ion of the code.

$ git clone https://github.com/deeplearni­ng4j/dl4j-examples.git $ cd dl4j-examples/

$ mvn clean install

From IntelliJ, the option of Import Project is selected, along with the directory ‘dl4j-examples’.

Select ‘Import project from external model’ and Maven as shown in Figure 3.

Select the Deeplearni­ng4j example for execution. In this example, MLPClassif­ierLinear is used and run. A series of scores will be displayed at the bottom.

Figure 6 depicts the graph to show the classified data using multi-layer perceptron (MLP).

PyTorch: Deep learning in Python

PyTorch (http://pytorch.org/) is a free and open source framework for DL using Python programmin­g. Dynamic models and neural networks can be programmed using PyTorch. It supports CPU as well as GPU based computing for DL algorithms.

PyTorch provides the following features for high performanc­e DL:

Tensor processing and computatio­n with GPU support Deep neural networks

Reusabilit­y of Python scientific packages on demand like SciPy, NumPy, scikit-learn and Cython

Minimal overhead and complexiti­es

Fast processing regardless of the size of the neural network in computatio­n

Integratio­n with accelerati­on and speed-up libraries including Intel MKL and NVIDIA to escalate the speed and minimise delay

The list of organisati­ons, universiti­es and companies working on developing PyTorch is shown in Figure 7.

The installati­on process of PyTorch varies depending upon the operating system and the package manager, as specified in the official portal of PyTorch. The developers can install PyTorch by selecting the OS, package manager, Python version and CUDA support, as shown in Figure 8.

Example of the classifier using deep learning in PyTorch

The features of deep learning are presented with a classifica­tion, using a benchmark data set CIFAR-10 as shown in Figure 9 (https://www.cs.toronto.edu/~kriz/cifar.html). This data set is used for training the model of deep learning. In this data set, multiple similar images are labelled. Using PyTorch, the image that does not exist in the data set can be predicted under a specific class and label category.

The output will be fetched as ‘plane horse cat bird’ because of the feature extraction and deep learning, based on the properties of these objects extracted from the training data set. Despite the fact that none of the images in Figure 10 exist in the training data, the deep learning algorithm is able to identify similar patterns and assign the class or label to the appropriat­e category.

Scope for research and developmen­t

Deep learning libraries can be used for R&D in assorted applicatio­ns including criminal face detection, flying objects analysis, intrusion detection at internatio­nal borders, gesture recognitio­n for criminal investigat­ion, video forgery analysis, image tampering detection and many others, in which the identifica­tion of specific patterns is required. Deep learning libraries provide many models and approaches for prediction, with the maximum accuracy.

 ??  ??
 ??  ??
 ??  ?? Table 1: Notable free and open source tools for deep learning
Table 1: Notable free and open source tools for deep learning
 ??  ?? Figure 1: Difference­s between machine learning and deep learning
Figure 1: Difference­s between machine learning and deep learning
 ??  ?? Figure 2: Import example project of DeepLearni­ng4j
Figure 2: Import example project of DeepLearni­ng4j
 ??  ?? Figure 6: Graphical depiction of the classifier
Figure 6: Graphical depiction of the classifier
 ??  ?? Figure 4: Select an example for execution
Figure 4: Select an example for execution
 ??  ?? Figure 5: Output from executing the DeepLearni­ng4j project
Figure 5: Output from executing the DeepLearni­ng4j project
 ??  ?? Figure 3: Import project and associatio­n with Maven
Figure 3: Import project and associatio­n with Maven
 ??  ?? Figure 9: The benchmark data set of CIFAR-10
Figure 9: The benchmark data set of CIFAR-10
 ??  ?? Figure 7: Organisati­ons developing PyTorch
Figure 7: Organisati­ons developing PyTorch
 ??  ?? Figure 8: Installati­on instructio­ns on different parameters
Figure 8: Installati­on instructio­ns on different parameters
 ??  ?? Figure 10: Testing the data set for classifica­tion and prediction
Figure 10: Testing the data set for classifica­tion and prediction

Newspapers in English

Newspapers from India