deeplearning4j icon indicating copy to clipboard operation
deeplearning4j copied to clipboard

Unable to get linear index >= 1 - after upgrading to 0.4-rc3.10

Open Alex-Cosma opened this issue 10 years ago • 4 comments

I have modified the basic Xor example a little bit such that it has only one output neuron instead of two.

 INDArray labels = Nd4j.zeros(4, 1);

        input.putScalar(new int[] { 0, 0 }, 0);
        input.putScalar(new int[] { 0, 1 }, 0);
        labels.putScalar(new int[] { 0, 0 }, 1);

        input.putScalar(new int[] { 1, 0 }, 1);
        input.putScalar(new int[] { 1, 1 }, 0);
        labels.putScalar(new int[] { 1, 0 }, 1);

        input.putScalar(new int[] { 2, 0 }, 0);
        input.putScalar(new int[] { 2, 1 }, 1);
        labels.putScalar(new int[] { 2, 0 }, 1);

        input.putScalar(new int[] { 3, 0 }, 1);
        input.putScalar(new int[] { 3, 1 }, 1);
        labels.putScalar(new int[] { 3, 0 }, 0);

for input and of course, modified the output layer to

        outputLayerBuilder.nOut(1);

Now the following code:

        Evaluation eval = new Evaluation(2);
        eval.eval(ds.getLabels(), output);
        System.out.println(eval.stats());

gives this error:

Exception in thread "main" java.lang.IllegalArgumentException: Unable to get linear index >= 1
    at org.nd4j.linalg.api.ndarray.BaseNDArray.getDouble(BaseNDArray.java:3248)
    at org.deeplearning4j.eval.Evaluation.eval(Evaluation.java:140)
    at org.deeplearning4j.examples.experiments.Xor.main(Xor.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

(Xor.java:167) = eval.eval(ds.getLabels(), output);

And I have no idea why.

Note, I have just now upgraded to 0.4-rc3.10 (basically copied the whole .pom file from here into my project) and before I did this, I was using the 0.4-rc3.8 version and this error did not occur!

Why is it so? Many thanks!

Alex-Cosma avatar Jun 14 '16 13:06 Alex-Cosma

Nout on the output layer has to be equal to the number of labels for evaluation.

agibsonccc avatar Jun 24 '16 16:06 agibsonccc

Why?

Alex-Cosma avatar Jun 24 '16 17:06 Alex-Cosma

Please come on gitter for clarifying questions thanks. On Jun 24, 2016 10:04 AM, "Cosma Alex" [email protected] wrote:

Why?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/deeplearning4j/deeplearning4j/issues/1685#issuecomment-228402398, or mute the thread https://github.com/notifications/unsubscribe/ABF18lWa953FJLyQnwIIDSacGjj1aPidks5qPA4VgaJpZM4I1UGl .

agibsonccc avatar Jun 24 '16 17:06 agibsonccc

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 20 '19 23:01 lock[bot]