Problem with DataAnalysis for Iris

Hi!

I’m currently applying the approach documented in Quickstart with Deeplearning4J to the Iris basic case.

I have correctly included in the pom.xml the required entries. The program compiles well but generates the following exception:

Exception in thread “main” java.util.NoSuchElementException: No more elements found!

It seems like there was a problem with the data, but I use exactly the iris.txt file of DL4J examples with 4 doubles and the class (0,1 or 2):

5.1,3.5,1.4,0.2,0

5.9,3.0,5.1,1.8,2

The code is as follows:

        Random random = new Random();
        random.setSeed(0xC0FFEE);
        FileSplit inputSplit = new FileSplit(new File("C:\\Users\\username\\dl4j-examples-data\\datavec-examples\\IrisData"), random);

        RecordReader recordReader = new CSVRecordReader();
        recordReader.initialize(inputSplit);

        //sepal length in cm
        //sepal width in cm
        //petal length in cm
        //petal width in cm
        //0 is Iris Setosa
        //1 is Iris Versicolour
        //2 is Iris Virginica
        Schema schema = new Schema.Builder()
                .addColumnsDouble("sepal length", "sepal width", "petal length", "petal width")
                .addColumnCategorical("Class", "0", "1", "2")
                .build();
        DataAnalysis analysis = AnalyzeLocal.analyze(schema, recordReader); // <===== GENERATES AN EXCEPTION

The exception is raised by the last line of code.
The rest of the code (not shown) to build the network, train, test and save the model runs fine if the code line above is set as a comment.

The detail error stack is:

Exception in thread "main" java.util.NoSuchElementException: No more elements found!
	at org.datavec.api.records.reader.impl.LineRecordReader.next(LineRecordReader.java:117)
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.readStringLine(CSVRecordReader.java:193)
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.next(CSVRecordReader.java:173)
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.nextRecord(CSVRecordReader.java:199)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.initializeUnderlying(RecordReaderDataSetIterator.java:194)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:341)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:421)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:53)
	at com.thenlpcy.mydl4jwebservernb.MyDL4JWebServerNB.main(MyDL4JWebServerNB.java:100)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:1000)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:947)
    at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:471)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:827)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:272)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:195)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Does anyone knows what may go wrong here?

@lbonansbrux could you post a direct link to a file I can just run so it’s easier for me to look at this? Thanks!

Hi Adam, a zip file containing the small Java Maven project and the data files is available under MyDL4JWebServerNB.zip - Google Drive

Before running the program, simply update the MyDL4JWebServerNB class static String variables with the path to the application’s current directory (lines 67 to 82).

To run the program:

mvn compile exec:java -Dexec.mainClass=com.thenlpcy.mydl4jwebservernb.MyDL4JWebServerNB

Line 121 generates the exception. If commented (with line 122), the program runs well and launches a Tomcat server, which main page is localhost:8080/go. From there 2 pages are available to make predictions.

If line 121 (and 122) are commented, I cannot benefit from the analysis to later on normalize the data in the prediction.

Thanks for your support!

@lbonansbrux

add:
recordReader.initialize(inputSplit);

before you call next().

           recordReader.initialize(inputSplit);

            DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader, batchSize, labelIndex, numClasses);
            DataSet allData = iterator.next();
            allData.shuffle();
            SplitTestAndTrain testAndTrain = allData.splitTestAndTrain(0.65);  //Use 65% of data for training

            DataSet trainingData = testAndTrain.getT

The issue was your analysis used up all the data in the record reader. The record reader maintains a current cursor. When it’s exhausted you need to reinitialize it. The same is true when you use the iterator. The iterator has a reset() method for this reason.

Many thanks Adam!

It works now!

Resolved.