Skip to content

Instantly share code, notes, and snippets.

@KeironO
Created February 22, 2015 18:02
Show Gist options
  • Save KeironO/9b91dfa424a905f5d02b to your computer and use it in GitHub Desktop.
Save KeironO/9b91dfa424a905f5d02b to your computer and use it in GitHub Desktop.
package org.deeplearning4j.eunice;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.deeplearning4j.datasets.fetchers.BaseDataFetcher;
import org.deeplearning4j.datasets.vectorizer.ImageVectorizer;
import org.deeplearning4j.datasets.vectorizer.Vectorizer;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;
import org.nd4j.linalg.util.ArrayUtil;
import org.deeplearning4j.datasets.vectorizer.ImageVectorizer;
import org.deeplearning4j.datasets.vectorizer.Vectorizer;
import org.deeplearning4j.distributions.Distributions;
import org.deeplearning4j.nn.WeightInit;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.nd4j.linalg.api.activation.Activations;
import org.nd4j.linalg.dataset.DataSet;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.deeplearning4j.datasets.fetchers.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
*
* @ (#) DiagnosingDouglasPouchObliteration.java 2015-02-17
*
* Copyright (c) 2015 Keiron-Teilo O'Shea
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public Licence as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
public class DiagnosingDouglasPouchObliteration extends BaseDataFetcher {
// Initalising the logger interface, the main user entry point.
// private static Logger log = LoggerFactory.getLogger(DiagnosingDouglasPouchObliteration.class);
public static void main(String args[]) {
}
@Override
public void fetch(int i) {
// Temporary solution, a GUI would be awesome for this.
File rootPath = new File ("/home/momo/dissertation/data set/videos of positive sliding sign from reproducibility study");
List<String> fileLabels = new ArrayList<String>();
//
// RandomGenerator numberGenerator = new MersenneTwister(123);
//
// NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder()
// .iterations(42)
// .weightInit(WeightInit.DISTRIBUTION).dist(Distributions.normal(numberGenerator,1e-3)).constrainGradientToUnitNorm(false)
// .lossFunction(LossFunctions.LossFunction.RECONSTRUCTION_CROSSENTROPY).activationFunction(Activations.tanh())
// .learningRate(1e-3f).nIn(4).nOut(3).build();
if(!rootPath.exists()) {
System.out.println("The files do not exist!");
}
for(File file : rootPath.listFiles()) {
if(file.isDirectory())
fileLabels.add(file.getName());
}
File rootDirectory = new File(fileLabels.toString()); // This that's wrong too.
for (String s : fileLabels) {
System.out.println(s);
}
List<DataSet> dataFilesVectorised = new ArrayList<>();
for(File f : rootDirectory.listFiles()) { //rootDirectory = root path on line 59.
if(f.isFile()) {
System.out.println(f.toString());
Vectorizer vectorizer = new ImageVectorizer(
f, // Image - the input image to convert
fileLabels.size(), // The number of labels
fileLabels.indexOf(f.getParentFile().getName())); // The label of these images
DataSet data = vectorizer.vectorize();
dataFilesVectorised.add(data);
}
initializeCurrFromList(dataFilesVectorised);
}
System.out.println(dataFilesVectorised.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment