DL4J

src/main/java/my/project/Main.java

package my.project;

import eu.neclab.sol.Input;
import eu.neclab.sol.Device;
import eu.neclab.sol.DeviceType;
import eu.neclab.sol.dl4j.DL4J;
import org.deeplearning4j.zoo.model.AlexNet;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.nd4j.linalg.factory.Nd4j;
import java.util.ArrayList;
import java.util.Arrays;

class Main {
	public static void main(String args[]) {
		try {
			Device.set(DeviceType.ve, 0);
			AlexNet dl4j_model = AlexNet.builder().numClasses(1000).seed(123).build();
			int[] inputSize = new int[]{1, 3, 224, 224};
			MultiLayerNetwork sol_model = DL4J.optimize(dl4j_model.init(), new ArrayList<Input>(Arrays.asList(new Input(inputSize, DType.F32, false))));
			INDArray input = Nd4j.zeros(inputSize);
			input = Nd4j.rand(input, 123);
			INDArray output = model.activate(input, Layer.TrainingMode.TEST);
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>my.project</groupId>
	<artifactId>MyProject</artifactId>
	<version>0.1</version>
	<packaging>jar</packaging>

	<properties>
		<java.version>1.8</java.version>
		<json.version>20190722</json.version>
    	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>eu.neclab.sol</groupId>
			<artifactId>sol-dl4j</artifactId>
			<version>0.3.1</version>
		</dependency>

		<dependency>
			<groupId>org.deeplearning4j</groupId>
			<artifactId>deeplearning4j-zoo</artifactId>
			<version>1.0.0-beta7</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>  
				<artifactId>exec-maven-plugin</artifactId>  
				<version>1.6.0</version>  
				<configuration>
					<mainClass>my.project.Main</mainClass>
				</configuration>
			</plugin>  
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Install SOL into Maven

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=/path/to/sol/dl4j/sol-dl4j-v0.3.2.jar

For details see: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Build Command

LD_LIBRARY_PATH=/path/to/sol/lib64 mvn clean compile exec:java

Supported Layers

  • ActivationLayer
    • ActivationSoftmax
    • ActivationReLU
    • ActivationReLU6
    • ActivationHardTanH
    • ActivationSigmoid
    • ActivationPReLU
    • ActivationTanH
    • ActivationSELU
    • ActivationSoftPlus
    • ActivationIdentity
    • ActivationLReLU
    • ActivationELU
    • ActivationRReLU
    • ActivationSoftSign
  • Add
  • BatchNormalization
  • MergeVertex
  • ConvolutionLayer
  • DenseLayer
  • DropoutLayer
  • GlobalPoolingLayer
  • LossLayer
  • OutputLayer
  • Product
  • Subtract
  • LocalResponseNormalization
  • ZeroPaddingLayer
  • SubsamplingLayer