Saturday, March 3, 2018

How to use DL4J on Android

1. Download Android Studio.
https://developer.android.com/studio/index.html

I am using Android Studio 3.2 Canary (As of Feb 2018, it is a preview version)
https://developer.android.com/studio/preview/index.html

2. Add these lines
compile 'org.deeplearning4j:deeplearning4j-core:0.8.0'
compile 'org.nd4j:nd4j-native:0.8.0'
compile 'org.nd4j:nd4j-native:0.8.0:android-x86'
compile 'org.nd4j:nd4j-native:0.8.0:android-arm'
compile 'org.bytedeco.javacpp-presets:openblas:0.2.19-1.3:android-x86'
compile 'org.bytedeco.javacpp-presets:openblas:0.2.19-1.3:android-arm'
to dependencies of build.grage (Module: app) like this:
(If you get some errors, see the official page: https://deeplearning4j.org/android#configuring-your-android-studio-project)

2. Sync the project.

3. Now you can import DL4J's classes and methods like this:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import org.deeplearning4j.nn.api.layers.*;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}