Merge pull request #7988 from alessiostalla/BAEL-18260

#BAEL-18260 Restructure ml and deeplearning4j modules
This commit is contained in:
Josh Cummings
2019-10-15 20:23:36 -06:00
committed by GitHub
10 changed files with 42 additions and 95 deletions

View File

@@ -1,6 +1,7 @@
## Deeplearning4j
This module contains articles about Deeplearning4j
This module contains articles about Deeplearning4j.
### Relevant Articles:
- [A Guide to Deeplearning4j](https://www.baeldung.com/deeplearning4j)
- [Logistic Regression in Java](https://www.baeldung.com/java-logistic-regression)

View File

@@ -14,6 +14,11 @@
</parent>
<dependencies>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
@@ -24,10 +29,26 @@
<artifactId>deeplearning4j-core</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nn</artifactId>
<version>${dl4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
<properties>
<dl4j.version>0.9.1</dl4j.version>
<dl4j.version>0.9.1</dl4j.version> <!-- Latest non beta version -->
</properties>
</project>
</project>

View File

@@ -3,9 +3,9 @@ package com.baeldung.deeplearning4j;
import org.datavec.api.records.reader.RecordReader;
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
import org.datavec.api.split.FileSplit;
import org.datavec.api.util.ClassPathResource;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
import org.deeplearning4j.eval.Evaluation;
import org.deeplearning4j.nn.conf.BackpropType;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
@@ -19,6 +19,7 @@ import org.nd4j.linalg.dataset.SplitTestAndTrain;
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
import org.nd4j.linalg.dataset.api.preprocessor.DataNormalization;
import org.nd4j.linalg.dataset.api.preprocessor.NormalizerStandardize;
import org.nd4j.linalg.io.ClassPathResource;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import java.io.IOException;
@@ -52,8 +53,8 @@ public class IrisClassifier {
.iterations(1000)
.activation(Activation.TANH)
.weightInit(WeightInit.XAVIER)
.learningRate(0.1)
.regularization(true).l2(0.0001)
.regularization(true)
.learningRate(0.1).l2(0.0001)
.list()
.layer(0, new DenseLayer.Builder().nIn(FEATURES_COUNT).nOut(3)
.build())
@@ -62,14 +63,14 @@ public class IrisClassifier {
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.activation(Activation.SOFTMAX)
.nIn(3).nOut(CLASSES_COUNT).build())
.backprop(true).pretrain(false)
.backpropType(BackpropType.Standard).pretrain(false)
.build();
MultiLayerNetwork model = new MultiLayerNetwork(configuration);
model.init();
model.fit(trainingData);
INDArray output = model.output(testData.getFeatureMatrix());
INDArray output = model.output(testData.getFeatures());
Evaluation eval = new Evaluation(CLASSES_COUNT);
eval.eval(testData.getLabels(), output);

View File

@@ -10,6 +10,7 @@ import org.datavec.api.split.FileSplit;
import org.datavec.image.loader.NativeImageLoader;
import org.datavec.image.recordreader.ImageRecordReader;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
import org.deeplearning4j.eval.Evaluation;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
@@ -21,15 +22,12 @@ import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.deeplearning4j.util.ModelSerializer;
import org.nd4j.evaluation.classification.Evaluation;
import org.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
import org.nd4j.linalg.dataset.api.preprocessor.DataNormalization;
import org.nd4j.linalg.dataset.api.preprocessor.ImagePreProcessingScaler;
import org.nd4j.linalg.learning.config.Nesterovs;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import org.nd4j.linalg.schedule.MapSchedule;
import org.nd4j.linalg.schedule.ScheduleType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,7 +42,7 @@ import org.slf4j.LoggerFactory;
public class MnistClassifier {
private static final Logger logger = LoggerFactory.getLogger(MnistClassifier.class);
private static final String basePath = System.getProperty("java.io.tmpdir") + "mnist" + File.separator;
private static final String basePath = System.getProperty("java.io.tmpdir") + File.separator + "mnist" + File.separator;
private static final File modelPath = new File(basePath + "mnist-model.zip");
private static final String dataUrl = "http://github.com/myleott/mnist_png/raw/master/mnist_png.tar.gz";
@@ -71,8 +69,7 @@ public class MnistClassifier {
String localFilePath = basePath + "mnist_png.tar.gz";
File file = new File(localFilePath);
if (!file.exists()) {
file.getParentFile()
.mkdirs();
file.getParentFile().mkdirs();
Utils.downloadAndSave(dataUrl, file);
Utils.extractTarArchive(file, basePath);
}
@@ -135,15 +132,15 @@ public class MnistClassifier {
.build();
final MultiLayerConfiguration config = new NeuralNetConfiguration.Builder().seed(seed)
.l2(0.0005) // ridge regression value
.updater(new Nesterovs(new MapSchedule(ScheduleType.ITERATION, learningRateSchedule)))
.updater(new Nesterovs()) //TODO new MapSchedule(ScheduleType.ITERATION, learningRateSchedule)
.weightInit(WeightInit.XAVIER)
.list()
.layer(layer1)
.layer(layer2)
.layer(layer3)
.layer(layer2)
.layer(layer4)
.layer(layer5)
.layer(0, layer1)
.layer(1, layer2)
.layer(2, layer3)
.layer(3, layer2)
.layer(4, layer4)
.layer(5, layer5)
.setInputType(InputType.convolutionalFlat(height, width, channels))
.build();
@@ -165,4 +162,4 @@ public class MnistClassifier {
ModelSerializer.writeModel(model, modelPath, true);
logger.info("The MINIST model has been saved in {}", modelPath.getPath());
}
}
}

View File

@@ -1,6 +0,0 @@
## Machine Learning
This module contains articles about Machine Learning (ML) in Java with [deeplearning4j](https://deeplearning4j.org).
### Relevant Articles:
- [Logistic Regression in Java](https://www.baeldung.com/)

View File

@@ -1,52 +0,0 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.deeplearning4j</groupId>
<artifactId>ml</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Machine Learning</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nn</artifactId>
<version>${dl4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
<properties>
<dl4j.version>1.0.0-beta4</dl4j.version>
</properties>
</project>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@@ -563,7 +563,6 @@
<module>metrics</module>
<!-- <module>micronaut</module> --> <!-- Fixing in BAEL-10877 -->
<module>microprofile</module>
<module>ml</module>
<module>msf4j</module>
<!-- <module>muleesb</module> --> <!-- Fixing in BAEL-10878 -->
<module>mustache</module>
@@ -1322,7 +1321,6 @@
<module>metrics</module>
<!-- <module>micronaut</module> --> <!-- Fixing in BAEL-10877 -->
<module>microprofile</module>
<module>ml</module>
<module>msf4j</module>
<!-- <module>muleesb</module> --> <!-- Fixing in BAEL-10878 -->
<module>mustache</module>