Deeplearning4j:无法获得线性索引> = 1(Deeplearning4j: unable to get linear index >= 1)

编程入门 行业动态 更新时间:2024-10-10 00:27:25
Deeplearning4j:无法获得线性索引> = 1(Deeplearning4j: unable to get linear index >= 1)

我正在尝试使用deeplearning4j训练神经网络。 但我收到此错误消息,我无法解释:

java.lang.reflect.InvocationTargetException 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:498) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: Unable to get linear index >= 1 at org.nd4j.linalg.api.ndarray.BaseNDArray.getDouble(BaseNDArray.java:3275) at org.deeplearning4j.eval.Evaluation.eval(Evaluation.java:197) at mypackage.myclass.main(Learn.java:77)

我的数据在csv文件中,它是64个数字(值为0,1,2,3),标签值为-1000到1000(浮点数)。

例如:

2,3,2,2,1,1,2,3,0,1,1,2,3,1,1,0,0,0,2,2,0,0,3,1,0,1,3,1,1,1,2,2,2,2,2,2,3, 2,2,2,2,3,3,1,2,2,1,3,0,0,2,3,2,3,2,0,0,3,0,1,1,3,3,2,-228.0

我使用此代码加载csv文件并训练网络:

RecordReader recordReader = new CSVRecordReader(0, ","); recordReader.initialize(new FileSplit(new File("data.csv"))); DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader, new DoubleWritableCo nverter(), 600000, 64, 64, true); DataSet allData = iterator.next(); SplitTestAndTrain testAndTrain = allData.splitTestAndTrain(0.9); DataSet trainingData = testAndTrain.getTrain(); DataSet testData = testAndTrain.getTest(); //We need to normalize our data. We'll use NormalizeStandardize (which gives us mean 0, unit variance): DataNormalization normalizer = new NormalizerStandardize(); normalizer.fit(trainingData); //Collect the statistics (mean/stdev) from the traini ng data. This does not modify the input data normalizer.transform(trainingData); //Apply normalization to the training data normalizer.transform(testData); //Apply normalization to the test data. This is using statistics calculated from the *training* set long seed = 123; int inputNum = 64; int hiddenNum = 64; int outputNum = 1; int iterations = 1; MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(seed) .activation("tanh") .iterations(iterations) .weightInit(WeightInit.XAVIER) .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .learningRate(0.1) .regularization(true).l2(1e-4) .list() .layer(0, new DenseLayer.Builder().nIn(inputNum).nOut(hiddenNum).build()) .layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.MSE) .activation("identity") .nIn(hiddenNum).nOut(outputNum).build()) .backprop(true).pretrain(false) .build(); MultiLayerNetwork model = new MultiLayerNetwork(conf); model.init(); model.setListeners(new ScoreIterationListener(100)); model.fit(trainingData); //evaluate the model on the test set Evaluation eval = new Evaluation(2); INDArray output = model.output(testData.getFeatureMatrix()); eval.eval(testData.getLabels(), output); <---- this is line 77, where the error occurs System.out.println(eval.stats()); recordReader.close();

这个错误意味着什么,我该如何解决这个问题?

I'm trying to train a neural network using deeplearning4j. But I get this error message which I cannot explain:

java.lang.reflect.InvocationTargetException 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:498) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: Unable to get linear index >= 1 at org.nd4j.linalg.api.ndarray.BaseNDArray.getDouble(BaseNDArray.java:3275) at org.deeplearning4j.eval.Evaluation.eval(Evaluation.java:197) at mypackage.myclass.main(Learn.java:77)

My data is in a csv file, it's 64 numbers (values 0,1,2,3) and a label of value -1000 to 1000 (floats).

for example:

2,3,2,2,1,1,2,3,0,1,1,2,3,1,1,0,0,0,2,2,0,0,3,1,0,1,3,1,1,1,2,2,2,2,2,2,3, 2,2,2,2,3,3,1,2,2,1,3,0,0,2,3,2,3,2,0,0,3,0,1,1,3,3,2,-228.0

I use this code to load the csv file and train the network:

RecordReader recordReader = new CSVRecordReader(0, ","); recordReader.initialize(new FileSplit(new File("data.csv"))); DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader, new DoubleWritableCo nverter(), 600000, 64, 64, true); DataSet allData = iterator.next(); SplitTestAndTrain testAndTrain = allData.splitTestAndTrain(0.9); DataSet trainingData = testAndTrain.getTrain(); DataSet testData = testAndTrain.getTest(); //We need to normalize our data. We'll use NormalizeStandardize (which gives us mean 0, unit variance): DataNormalization normalizer = new NormalizerStandardize(); normalizer.fit(trainingData); //Collect the statistics (mean/stdev) from the traini ng data. This does not modify the input data normalizer.transform(trainingData); //Apply normalization to the training data normalizer.transform(testData); //Apply normalization to the test data. This is using statistics calculated from the *training* set long seed = 123; int inputNum = 64; int hiddenNum = 64; int outputNum = 1; int iterations = 1; MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(seed) .activation("tanh") .iterations(iterations) .weightInit(WeightInit.XAVIER) .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .learningRate(0.1) .regularization(true).l2(1e-4) .list() .layer(0, new DenseLayer.Builder().nIn(inputNum).nOut(hiddenNum).build()) .layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.MSE) .activation("identity") .nIn(hiddenNum).nOut(outputNum).build()) .backprop(true).pretrain(false) .build(); MultiLayerNetwork model = new MultiLayerNetwork(conf); model.init(); model.setListeners(new ScoreIterationListener(100)); model.fit(trainingData); //evaluate the model on the test set Evaluation eval = new Evaluation(2); INDArray output = model.output(testData.getFeatureMatrix()); eval.eval(testData.getLabels(), output); <---- this is line 77, where the error occurs System.out.println(eval.stats()); recordReader.close();

What does this error mean and how can I fix this?

最满意答案

您为评估指定了2个标签。 然后在回归问题上使用eval。

Eval主要用于分类。 您必须手动进行自己的回归评估。

You are specifying 2 labels for the evaluation. and then using eval on a regression problem.

Eval is mainly meant for classification. You'll have to hand roll your own regression evaluation.

更多推荐

本文发布于:2023-08-07 11:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464305.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线性   索引   Deeplearning4j   index   linear

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!