java - dl4j canova example not working -
deeplearning4j canova example not working.i getting output of eval.stats nan (accuracy).i
import org.slf4j.loggerfactory; public class imageclassifierexample { public static void main(string[] args) throws ioexception, interruptedexception { // path labeled images string labeledpath = system.getproperty("user.home")+"/lfw"; list<string> labels = new arraylist<>(); for(file f : new file(labeledpath).listfiles()) { labels.add(f.getname()); } // instantiating recordreader pointing data path specified // height , width each image. recordreader recordreader = new imagerecordreader(28, 28, true,labels); recordreader.initialize(new filesplit(new file(labeledpath))); // canova dl4j datasetiterator iter = new recordreaderdatasetiterator(recordreader, 784,labels.size()); // creating configuration neural net. multilayerconfiguration conf = new neuralnetconfiguration.builder() .optimizationalgo(optimizationalgorithm.conjugate_gradient) .constraingradienttounitnorm(true) .weightinit(weightinit.distribution) .dist(new normaldistribution(1,1e-5)) .iterations(100).learningrate(1e-3) .nin(784).nout(labels.size()) .visibleunit(org.deeplearning4j.nn.conf.layers.rbm.visibleunit.gaussian) .hiddenunit(org.deeplearning4j.nn.conf.layers.rbm.hiddenunit.rectified) .layer(new org.deeplearning4j.nn.conf.layers.rbm()) .list(4).hiddenlayersizes(600, 250, 100).override(3, new confoverride() { @override public void overridelayer(int i, neuralnetconfiguration.builder builder) { if (i == 3) { builder.layer(new org.deeplearning4j.nn.conf.layers.outputlayer()); builder.activationfunction("softmax"); builder.lossfunction(lossfunctions.lossfunction.mcxent); } } }).build(); multilayernetwork network = new multilayernetwork(conf); network.setlisteners(arrays.<iterationlistener>aslist(new scoreiterationlistener(10))); // training while(iter.hasnext()){ dataset next = iter.next(); network.fit(next); } // testing -- we're not doing split test , train // using same training data test. iter.reset(); evaluation eval = new evaluation(); while(iter.hasnext()){ dataset next = iter.next(); indarray predict2 = network.output(next.getfeaturematrix()); eval.eval(next.getlabels(), predict2); } system.out.println(eval.stats()); } }
your nn configuration looks it's based on old dl4j version. current release versions are:
dl4j: 0.4-rc3.8 nd4j: 0.4-rc3.8 canova: 0.0.0.14
please, try use recent versions
Comments
Post a Comment