Skip to content

Commit 85ad7d8

Browse files
author
Philip Khor
committed
2 parents f42b7d4 + f01ad35 commit 85ad7d8

File tree

81 files changed

+575
-692
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+575
-692
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ Word2vec-index/
6161
!tutorials/*.json
6262
*end.model
6363

64+
arbiterExample/

android/DL4JImageRecognitionDemo/app/build.gradle

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,33 @@ android {
6464
implementation 'com.android.support:appcompat-v7:27.1.0'
6565
implementation 'com.android.support:design:27.1.0'
6666

67-
compile (group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta5') {
67+
implementation (group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta5') {
6868
exclude group: 'org.bytedeco', module: 'opencv-platform'
6969
exclude group: 'org.bytedeco', module: 'leptonica-platform'
7070
exclude group: 'org.bytedeco', module: 'hdf5-platform'
7171
exclude group: 'org.nd4j', module: 'nd4j-base64'
7272
}
7373

74-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5'
75-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm"
76-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm64"
77-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86"
78-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86_64"
79-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5'
80-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm"
81-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm64"
82-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86"
83-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86_64"
84-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5'
85-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm"
86-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm64"
87-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86"
88-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86_64"
89-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5'
90-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm"
91-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm64"
92-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86"
93-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86_64"
74+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5'
75+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm"
76+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm64"
77+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86"
78+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86_64"
79+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5'
80+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm"
81+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm64"
82+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86"
83+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86_64"
84+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5'
85+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm"
86+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm64"
87+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86"
88+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86_64"
89+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5'
90+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm"
91+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm64"
92+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86"
93+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86_64"
9494

9595
implementation 'com.google.code.gson:gson:2.8.2'
9696
annotationProcessor 'org.projectlombok:lombok:1.16.16'
@@ -102,7 +102,7 @@ android {
102102
}
103103

104104

105-
compile 'com.google.code.findbugs:annotations:3.0.1', {
105+
implementation 'com.google.code.findbugs:annotations:3.0.1', {
106106
exclude module: 'jsr305'
107107
exclude module: 'jcip-annotations'
108108
}

android/DL4JImageRecognitionDemo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ buildscript {
2323
jcenter()
2424
}
2525
dependencies {
26-
classpath 'com.android.tools.build:gradle:3.0.1'
26+
classpath 'com.android.tools.build:gradle:3.4.2'
2727

2828

2929
// NOTE: Do not place your application dependencies here; they belong

android/DL4JIrisClassifierDemo/app/build.gradle

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,45 +66,44 @@ android {
6666
implementation 'com.android.support:design:27.1.0'
6767

6868

69-
compile (group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta5') {
69+
implementation (group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta5') {
7070
exclude group: 'org.bytedeco', module: 'opencv-platform'
7171
exclude group: 'org.bytedeco', module: 'leptonica-platform'
7272
exclude group: 'org.bytedeco', module: 'hdf5-platform'
7373
exclude group: 'org.nd4j', module: 'nd4j-base64'
7474
}
75-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5'
76-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm"
77-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm64"
78-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86"
79-
compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86_64"
80-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5'
81-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm"
82-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm64"
83-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86"
84-
compile group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86_64"
85-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5'
86-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm"
87-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm64"
88-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86"
89-
compile group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86_64"
90-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5'
91-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm"
92-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm64"
93-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86"
94-
compile group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86_64"
75+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5'
76+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm"
77+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm64"
78+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86"
79+
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86_64"
80+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5'
81+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm"
82+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-arm64"
83+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86"
84+
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.5-1.5', classifier: "android-x86_64"
85+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5'
86+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm"
87+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-arm64"
88+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86"
89+
implementation group: 'org.bytedeco', name: 'opencv', version: '4.0.1-1.5', classifier: "android-x86_64"
90+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5'
91+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm"
92+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-arm64"
93+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86"
94+
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5', classifier: "android-x86_64"
9595

9696
implementation 'com.google.code.gson:gson:2.8.2'
9797
annotationProcessor 'org.projectlombok:lombok:1.16.16'
9898

99-
implementation 'com.google.code.findbugs:annotations:3.0.1', {
100-
exclude module: 'jsr305'
101-
exclude module: 'jcip-annotations'
102-
}
10399

104100
//This corrects for a junit version conflict.
105101
configurations.all {
106102
resolutionStrategy.force 'junit:junit:4.12'
107-
103+
}
104+
compileOptions {
105+
sourceCompatibility JavaVersion.VERSION_1_8
106+
targetCompatibility JavaVersion.VERSION_1_8
108107
}
109108

110109
}}

android/DL4JIrisClassifierDemo/app/src/main/java/org/deeplearning4j/examples/iris_classifier/MainActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ protected String doInBackground(Double... params) {
180180
listBuilder.layer(1, hiddenLayer);
181181
listBuilder.layer(2, outputLayer);
182182

183-
listBuilder.backprop(true);
184-
185183
MultiLayerNetwork myNetwork = new MultiLayerNetwork(listBuilder.build());
186184
myNetwork.init();
187185

android/DL4JIrisClassifierDemo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildscript {
3030

3131
}
3232
dependencies {
33-
classpath 'com.android.tools.build:gradle:3.0.1'
33+
classpath 'com.android.tools.build:gradle:3.4.2'
3434

3535
// NOTE: Do not place your application dependencies here; they belong
3636
// in the individual module build.gradle files

dl4j-examples/src/main/java/org/deeplearning4j/examples/arbiter/BasicHyperparameterOptimizationExample.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*******************************************************************************
1+
/* *****************************************************************************
22
* Copyright (c) 2015-2019 Skymind, Inc.
33
*
44
* This program and the accompanying materials are made available under the
@@ -42,11 +42,11 @@
4242
import org.deeplearning4j.arbiter.task.MultiLayerNetworkTaskCreator;
4343
import org.deeplearning4j.arbiter.ui.listener.ArbiterStatusListener;
4444
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
45-
import org.deeplearning4j.eval.Evaluation;
4645
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
4746
import org.deeplearning4j.nn.weights.WeightInit;
4847
import org.deeplearning4j.ui.api.UIServer;
4948
import org.deeplearning4j.ui.storage.FileStatsStorage;
49+
import org.nd4j.evaluation.classification.Evaluation.Metric;
5050
import org.nd4j.linalg.activations.Activation;
5151
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
5252
import org.nd4j.linalg.lossfunctions.LossFunctions;
@@ -114,14 +114,16 @@ public static void main(String[] args) throws Exception {
114114
// This will result in examples being saved to arbiterExample/0/, arbiterExample/1/, arbiterExample/2/, ...
115115
String baseSaveDirectory = "arbiterExample/";
116116
File f = new File(baseSaveDirectory);
117-
if (f.exists()) f.delete();
117+
if (f.exists()) //noinspection ResultOfMethodCallIgnored
118+
f.delete();
119+
//noinspection ResultOfMethodCallIgnored
118120
f.mkdir();
119121
ResultSaver modelSaver = new FileModelSaver(baseSaveDirectory);
120122

121123
// (d) What are we actually trying to optimize?
122124
// In this example, let's use classification accuracy on the test set
123125
// See also ScoreFunctions.testSetF1(), ScoreFunctions.testSetRegression(regressionValue) etc
124-
ScoreFunction scoreFunction = new EvaluationScoreFunction(Evaluation.Metric.ACCURACY);
126+
ScoreFunction scoreFunction = new EvaluationScoreFunction(Metric.ACCURACY);
125127

126128

127129
// (e) When should we stop searching? Specify this with termination conditions

dl4j-examples/src/main/java/org/deeplearning4j/examples/arbiter/genetic/BaseGeneticHyperparameterOptimizationExample.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*******************************************************************************
1+
/* *****************************************************************************
22
* Copyright (c) 2015-2019 Skymind, Inc.
33
*
44
* This program and the accompanying materials are made available under the
@@ -25,9 +25,10 @@
2525
import org.deeplearning4j.arbiter.optimize.generator.genetic.population.PopulationModel;
2626
import org.deeplearning4j.arbiter.optimize.runner.IOptimizationRunner;
2727
import org.deeplearning4j.arbiter.scoring.impl.EvaluationScoreFunction;
28-
import org.deeplearning4j.eval.Evaluation;
2928
import org.deeplearning4j.nn.graph.ComputationGraph;
29+
import org.nd4j.evaluation.classification.Evaluation.Metric;
3030

31+
import java.io.IOException;
3132
import java.util.List;
3233

3334
/**
@@ -38,23 +39,13 @@
3839
*
3940
* @author Alexandre Boulanger
4041
*/
41-
4242
public class BaseGeneticHyperparameterOptimizationExample {
4343

44-
public static void main(String[] args) throws Exception {
45-
46-
ComputationGraphSpace cgs = GeneticSearchExampleConfiguration.GetGraphConfiguration();
47-
48-
EvaluationScoreFunction scoreFunction = new EvaluationScoreFunction(Evaluation.Metric.F1);
49-
50-
// This is where we create the GeneticSearchCandidateGenerator with its default behavior:
51-
// - a population that fits 30 candidates and is culled back to 20 when it overflows
52-
// - new candidates are generated with a probability of 85% of being the result of breeding (a k-point crossover with 1 to 4 points)
53-
// - the new candidate have a probability of 0.5% of sustaining a random mutation on one of its genes.
54-
GeneticSearchCandidateGenerator candidateGenerator = new GeneticSearchCandidateGenerator.Builder(cgs, scoreFunction).build();
55-
56-
// Let's have a listener to print the population size after each evaluation.
57-
PopulationModel populationModel = candidateGenerator.getPopulationModel();
44+
/**
45+
* Common code used by two Arbiter examples.
46+
*/
47+
public static void run(PopulationModel populationModel, GeneticSearchCandidateGenerator candidateGenerator,
48+
EvaluationScoreFunction scoreFunction) throws IOException {
5849
populationModel.addListener(new ExamplePopulationListener());
5950

6051
IOptimizationRunner runner = GeneticSearchExampleConfiguration.BuildRunner(candidateGenerator, scoreFunction);
@@ -80,13 +71,32 @@ public static void main(String[] args) throws Exception {
8071
System.out.println(bestModel.getConfiguration().toJson());
8172
}
8273

74+
public static void main(String[] args) throws Exception {
75+
76+
ComputationGraphSpace cgs = GeneticSearchExampleConfiguration.GetGraphConfiguration();
77+
78+
EvaluationScoreFunction scoreFunction = new EvaluationScoreFunction(Metric.F1);
79+
80+
// This is where we create the GeneticSearchCandidateGenerator with its default behavior:
81+
// - a population that fits 30 candidates and is culled back to 20 when it overflows
82+
// - new candidates are generated with a probability of 85% of being the result of breeding (a k-point crossover with 1 to 4 points)
83+
// - the new candidate have a probability of 0.5% of sustaining a random mutation on one of its genes.
84+
GeneticSearchCandidateGenerator candidateGenerator = new GeneticSearchCandidateGenerator.Builder(cgs, scoreFunction).build();
85+
86+
// Let's have a listener to print the population size after each evaluation.
87+
PopulationModel populationModel = candidateGenerator.getPopulationModel();
88+
populationModel.addListener(new ExamplePopulationListener());
89+
run(populationModel, candidateGenerator, scoreFunction);
90+
}
91+
8392
public static class ExamplePopulationListener implements PopulationListener {
8493

94+
@SuppressWarnings("OptionalGetWithoutIsPresent")
8595
@Override
8696
public void onChanged(List<Chromosome> population) {
8797
double best = population.get(0).getFitness();
8898
double average = population.stream()
89-
.mapToDouble(c -> c.getFitness())
99+
.mapToDouble(Chromosome::getFitness)
90100
.average()
91101
.getAsDouble();
92102
System.out.println(String.format("\nPopulation size is %1$s, best score is %2$s, average score is %3$s", population.size(), best, average));

0 commit comments

Comments
 (0)