Skip to content

Commit 861316d

Browse files
committed
wip.
Signed-off-by: Robert Altena <[email protected]>
1 parent 8e1b23c commit 861316d

File tree

10 files changed

+32
-46
lines changed

10 files changed

+32
-46
lines changed

dl4j-examples/src/main/java/org/deeplearning4j/examples/convolution/Cifar.java

Lines changed: 3 additions & 5 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
@@ -43,8 +43,6 @@
4343
import org.slf4j.LoggerFactory;
4444

4545
import java.io.File;
46-
import java.io.IOException;
47-
4846

4947
/**
5048
* train model by cifar
@@ -55,8 +53,8 @@
5553
*/
5654

5755
//@Slf4j
56+
@SuppressWarnings("FieldCanBeLocal")
5857
public class Cifar {
59-
private static final File DATA_PATH = new File(System.getProperty("user.dir"));
6058
protected static final Logger log = LoggerFactory.getLogger(Cifar.class);
6159

6260
private static int height = 32;
@@ -89,7 +87,7 @@ public static void main(String[] args) throws Exception {
8987
}
9088

9189

92-
public MultiLayerNetwork getModel() throws IOException {
90+
public MultiLayerNetwork getModel() {
9391
log.info("Building simple convolutional network...");
9492
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
9593
.seed(seed)

dl4j-examples/src/main/java/org/deeplearning4j/examples/convolution/LenetMnistExample.java

Lines changed: 1 addition & 1 deletion
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

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/BasicCSVClassifier.java

Lines changed: 10 additions & 26 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
@@ -70,6 +70,7 @@ public class BasicCSVClassifier {
7070

7171
public static String dataLocalPath;
7272

73+
@SuppressWarnings("DuplicatedCode")
7374
public static void main(String[] args) throws Exception {
7475
dataLocalPath = DownloaderUtility.DATAEXAMPLES.Download();
7576
eats = readEnumCSV("animals/eats.csv");
@@ -141,12 +142,12 @@ public static void main(String[] args) throws Exception {
141142
logAnimals(animals);
142143
}
143144

144-
public static void logAnimals(Map<Integer, Map<String, Object>> animals) {
145+
private static void logAnimals(Map<Integer, Map<String, Object>> animals) {
145146
for (Map<String, Object> a : animals.values())
146147
log.info(a.toString());
147148
}
148149

149-
public static void setFittedClassifiers(INDArray output, Map<Integer, Map<String, Object>> animals) {
150+
private static void setFittedClassifiers(INDArray output, Map<Integer, Map<String, Object>> animals) {
150151
for (int i = 0; i < output.rows(); i++) {
151152

152153
// set the classification from the fitted results
@@ -159,11 +160,8 @@ public static void setFittedClassifiers(INDArray output, Map<Integer, Map<String
159160
* This method is to show how to convert the INDArray to a float array. This is to
160161
* provide some more examples on how to convert INDArray to types that are more java
161162
* centric.
162-
*
163-
* @param rowSlice
164-
* @return
165163
*/
166-
public static float[] getFloatArrayFromSlice(INDArray rowSlice) {
164+
private static float[] getFloatArrayFromSlice(INDArray rowSlice) {
167165
float[] result = new float[rowSlice.columns()];
168166
for (int i = 0; i < rowSlice.columns(); i++) {
169167
result[i] = rowSlice.getFloat(i);
@@ -174,11 +172,8 @@ public static float[] getFloatArrayFromSlice(INDArray rowSlice) {
174172
/**
175173
* find the maximum item index. This is used when the data is fitted and we
176174
* want to determine which class to assign the test row to
177-
*
178-
* @param vals
179-
* @return
180175
*/
181-
public static int maxIndex(float[] vals) {
176+
private static int maxIndex(float[] vals) {
182177
int maxIndex = 0;
183178
for (int i = 1; i < vals.length; i++) {
184179
float newnumber = vals[i];
@@ -192,17 +187,14 @@ public static int maxIndex(float[] vals) {
192187
/**
193188
* take the dataset loaded for the matric and make the record model out of it so
194189
* we can correlate the fitted classifier to the record.
195-
*
196-
* @param testData
197-
* @return
198190
*/
199-
public static Map<Integer, Map<String, Object>> makeAnimalsForTesting(DataSet testData) {
191+
private static Map<Integer, Map<String, Object>> makeAnimalsForTesting(DataSet testData) {
200192
Map<Integer, Map<String, Object>> animals = new HashMap<>();
201193

202194
INDArray features = testData.getFeatures();
203195
for (int i = 0; i < features.rows(); i++) {
204196
INDArray slice = features.slice(i);
205-
Map<String, Object> animal = new HashMap();
197+
Map<String, Object> animal = new HashMap<>();
206198

207199
//set the attributes
208200
animal.put("yearsLived", slice.getInt(0));
@@ -216,7 +208,7 @@ public static Map<Integer, Map<String, Object>> makeAnimalsForTesting(DataSet te
216208
}
217209

218210

219-
public static Map<Integer, String> readEnumCSV(String csvFileClasspath) {
211+
private static Map<Integer, String> readEnumCSV(String csvFileClasspath) {
220212
try {
221213
List<String> lines = IOUtils.readLines(new FileInputStream(new File(dataLocalPath, csvFileClasspath)), StandardCharsets.UTF_8);
222214
Map<Integer, String> enums = new HashMap<>();
@@ -232,15 +224,7 @@ public static Map<Integer, String> readEnumCSV(String csvFileClasspath) {
232224
}
233225

234226
/**
235-
* used for testing and training
236-
*
237-
* @param csvFileClasspath
238-
* @param batchSize
239-
* @param labelIndex
240-
* @param numClasses
241-
* @return
242-
* @throws IOException
243-
* @throws InterruptedException
227+
* used for testing and training*
244228
*/
245229
private static DataSet readCSVDataset(
246230
String csvFileClasspath, int batchSize, int labelIndex, int numClasses)

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/CSVExample.java

Lines changed: 3 additions & 2 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
@@ -20,7 +20,6 @@
2020
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
2121
import org.datavec.api.split.FileSplit;
2222
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
23-
import org.deeplearning4j.eval.Evaluation;
2423
import org.deeplearning4j.examples.download.DownloaderUtility;
2524
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
2625
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
@@ -29,6 +28,7 @@
2928
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
3029
import org.deeplearning4j.nn.weights.WeightInit;
3130
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
31+
import org.nd4j.evaluation.classification.Evaluation;
3232
import org.nd4j.linalg.activations.Activation;
3333
import org.nd4j.linalg.api.ndarray.INDArray;
3434
import org.nd4j.linalg.dataset.DataSet;
@@ -46,6 +46,7 @@
4646
/**
4747
* @author Adam Gibson
4848
*/
49+
@SuppressWarnings("DuplicatedCode")
4950
public class CSVExample {
5051

5152
private static Logger log = LoggerFactory.getLogger(CSVExample.class);

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/CSVExampleEvaluationMetaData.java

Lines changed: 3 additions & 2 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
@@ -23,7 +23,6 @@
2323
import org.datavec.api.split.FileSplit;
2424
import org.datavec.api.writable.Writable;
2525
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
26-
import org.deeplearning4j.eval.Evaluation;
2726
import org.deeplearning4j.examples.download.DownloaderUtility;
2827
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
2928
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
@@ -32,6 +31,7 @@
3231
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
3332
import org.deeplearning4j.nn.weights.WeightInit;
3433
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
34+
import org.nd4j.evaluation.classification.Evaluation;
3535
import org.nd4j.evaluation.meta.Prediction;
3636
import org.nd4j.linalg.activations.Activation;
3737
import org.nd4j.linalg.api.ndarray.INDArray;
@@ -55,6 +55,7 @@
5555
*/
5656
public class CSVExampleEvaluationMetaData {
5757

58+
@SuppressWarnings("unused")
5859
public static void main(String[] args) throws Exception {
5960
//First: get the dataset using the record reader. This is as per CSV example - see that example for details
6061
RecordReader recordReader = new CSVRecordReader(0, ',');

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/CSVPlotter.java

Lines changed: 2 additions & 1 deletion
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
@@ -185,6 +185,7 @@ private static void plotDataset(ArrayList<DataSet> DataSetList) {
185185
boolean legend = false;
186186
boolean tooltips = false;
187187
boolean urls = false;
188+
//noinspection ConstantConditions
188189
JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, c, orientation, legend, tooltips, urls);
189190
JPanel panel = new ChartPanel(chart);
190191

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/ImagePipelineExample.java

Lines changed: 1 addition & 1 deletion
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

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/KFoldIteratorExample.java

Lines changed: 1 addition & 1 deletion
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

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/MapFileConversion.java

Lines changed: 1 addition & 1 deletion
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

dl4j-examples/src/main/java/org/deeplearning4j/examples/dataexamples/MnistImagePipelineExample.java

Lines changed: 7 additions & 6 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
@@ -62,14 +62,15 @@
6262
* handwritten image 3 (for example) was read from directory 3, has a matrix with the shown values,
6363
* has a label value corresponding to 3
6464
*/
65+
@SuppressWarnings("ResultOfMethodCallIgnored")
6566
public class MnistImagePipelineExample {
6667
private static Logger log = LoggerFactory.getLogger(MnistImagePipelineExample.class);
6768

6869
/** Data URL for downloading */
69-
public static final String DATA_URL = "http://github.com/myleott/mnist_png/raw/master/mnist_png.tar.gz";
70+
private static final String DATA_URL = "http://github.com/myleott/mnist_png/raw/master/mnist_png.tar.gz";
7071

7172
/** Location to save and extract the training/testing data */
72-
public static final String DATA_PATH = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "dl4j_Mnist/");
73+
private static final String DATA_PATH = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "dl4j_Mnist/");
7374

7475
public static void main(String[] args) throws Exception {
7576
/*
@@ -142,7 +143,7 @@ The classes downloadData, getMnistPNG(),
142143
and extractTarGz are for downloading and extracting the data
143144
*/
144145

145-
protected static void downloadData() throws Exception {
146+
static void downloadData() throws Exception {
146147
// Create directory if required
147148
File directory = new File(DATA_PATH);
148149
if (!directory.exists())
@@ -171,7 +172,8 @@ protected static void downloadData() throws Exception {
171172
}
172173
}
173174

174-
public static void getMnistPNG() throws IOException {
175+
@SuppressWarnings("PlaceholderCountMatchesArgumentCount")
176+
private static void getMnistPNG() throws IOException {
175177
String tmpDirStr = System.getProperty("java.io.tmpdir");
176178
String archizePath = DATA_PATH + "/mnist_png.tar.gz";
177179

@@ -187,5 +189,4 @@ public static void getMnistPNG() throws IOException {
187189
log.info("Using existing directory at ", f.getAbsolutePath());
188190
}
189191
}
190-
191192
}

0 commit comments

Comments
 (0)