Problem in loading input of 1D CNN for regression

Hi, first I should say that I am new in DL4J.
I want to train a 1D CNN for a regression problem.
My input is a 10000 samples of 1D vector with the size of 2048 points. the output is 21 parameters.
I created the CNN, you can see at the end.
the input is a CSV (or NDArray, It does not matter, I can convert it), and output is a CSV file too. I wrote this piece of code for reading input but I do not know how i can load input and output together as DataSetIterator?!

        RecordReader recordReader = new CSVRecordReader(0,',');
        recordReader.initialize(new FileSplit(new File("D:\\deep fitting\\Labels.csv")));
        DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader,10000);
        DataSet allData = iterator.next();

anthor thing that bears in my mind is using INDArrayDataSetIterator, but I do not know HOW?
I appriciate your help in advance :slight_smile:
My Net:

        MultiLayerConfiguration configuration = new NeuralNetConfiguration.Builder()
            .seed(seed)
            .updater(new AdaDelta())
            .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
            .weightInit(WeightInit.XAVIER)
            .list()
            .layer(new Convolution1DLayer.Builder().kernelSize(5).convolutionMode(ConvolutionMode.Same)
                .nIn(1).nOut(16).build())
            .layer(new Subsampling1DLayer.Builder().kernelSize(2).stride(2).poolingType(SubsamplingLayer.PoolingType.MAX).build())
            .layer(new Convolution1DLayer.Builder().kernelSize(5).convolutionMode(ConvolutionMode.Same).activation(Activation.LEAKYRELU)
                .nOut(32).build())
            .layer(new Subsampling1DLayer.Builder().kernelSize(2).stride(2).build())
            .layer(new Convolution1DLayer.Builder().kernelSize(5).convolutionMode(ConvolutionMode.Same).activation(Activation.LEAKYRELU)
                .nOut(64).build())
            .layer(new Subsampling1DLayer.Builder().kernelSize(2).stride(2).build())
            .layer(new Convolution1DLayer.Builder().kernelSize(3).convolutionMode(ConvolutionMode.Same).activation(Activation.LEAKYRELU)
                .nOut(128).build())
            .layer(new Subsampling1DLayer.Builder().kernelSize(2).stride(2).build())
            .layer(new Convolution1DLayer.Builder().kernelSize(3).convolutionMode(ConvolutionMode.Same).activation(Activation.LEAKYRELU)
                .nOut(256).build())
            .layer(new Subsampling1DLayer.Builder().kernelSize(2).stride(2).build())
            .layer(new Convolution1DLayer.Builder().kernelSize(3).convolutionMode(ConvolutionMode.Same).activation(Activation.LEAKYRELU)
                .nOut(512).build())
            .layer(new Subsampling1DLayer.Builder().kernelSize(2).stride(2).build())
            .layer(new DropoutLayer(0.2))
            .layer(new DenseLayer.Builder().nOut(21).build())
            .layer(new OutputLayer.Builder(LossFunctions.LossFunction.MSE)
                .name("output")
                .nOut(21)
                .activation(Activation.IDENTITY).build())
            .setInputType(InputType.convolutional(1,2048,1))
            .build();

        MultiLayerNetwork network = new MultiLayerNetwork(configuration);
        network.init();

So you have a CSV file, that has 2048 features and 10000 examples, and you have another one that has the same 10000 examples and 21 output values. And now you are struggling to create a DataSetIterator that uses the first file as features and the second file as labels.
Have I understood your question correctly?

Thank you very much @treo. yes, you have understood correctly.
in other words, I have an NDArray with the size of 10000 * 2048 as the input, and another NDArray with the size of 10000 * 21 as the output. How convert these matrices to input for my CNN.

  • I will add another channel to input matrix(10000 * 2048 * 2), but first I must solve this problem.

The easiest way to solve this, would be to just have both inputs and outputs in your csv file and construct your dataset iterator for regression, as you can see here:
https://deeplearning4j.org/api/latest/org/deeplearning4j/datasets/datavec/RecordReaderDataSetIterator.html

Thanks a lot. I will try this, but In case I have just two NDArrays (Indeed, raw data is a double array), Is it possible to use INDArrayDataSetIterator?

If your raw data comes in as a double array, then it may be easier to go for the DoubleDataSetIterator, you pass a collection of individual feature + label pairs, and give it the batch size it should be using.

thanks @treo it works