# Problem in loading input of 1D CNN for regression

**URL:** <https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280>\
**Category:** DataVec\
**Created:** [March 18, 2020, 10:32am UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280 "2020-03-18T10:32:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirshamaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/amirshamaei/32/100_2.png) [@amirshamaei](https://community.konduit.ai/u/amirshamaei)\
**Post date:** [March 18, 2020, 10:32am UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/1 "2020-03-18T10:32:21Z")

</div>

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?!

```java
        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 🙂  
My Net:

```java
        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();

```

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [March 18, 2020, 10:56am UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/2 "2020-03-18T10:56:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![amirshamaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/amirshamaei/32/100_2.png) [@amirshamaei](https://community.konduit.ai/u/amirshamaei)\
**Post date:** [March 18, 2020, 11:20am UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/3 "2020-03-18T11:20:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [March 18, 2020, 11:56am UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/4 "2020-03-18T11:56:00Z")

</div>

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](https://deeplearning4j.org/api/latest/org/deeplearning4j/datasets/datavec/RecordReaderDataSetIterator.html)

---

<div class="post-metadata">

**Author:** ![amirshamaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/amirshamaei/32/100_2.png) [@amirshamaei](https://community.konduit.ai/u/amirshamaei)\
**Post date:** [March 18, 2020, 2:13pm UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/5 "2020-03-18T14:13:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [March 18, 2020, 2:20pm UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/6 "2020-03-18T14:20:35Z")

</div>

If your raw data comes in as a double array, then it may be easier to go for the [DoubleDataSetIterator](https://deeplearning4j.org/api/latest/org/deeplearning4j/datasets/iterator/DoublesDataSetIterator.html), you pass a collection of individual feature + label pairs, and give it the batch size it should be using.

---

<div class="post-metadata">

**Author:** ![amirshamaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/amirshamaei/32/100_2.png) [@amirshamaei](https://community.konduit.ai/u/amirshamaei)\
**Post date:** [March 19, 2020, 10:44am UTC](https://community.konduit.ai/t/problem-in-loading-input-of-1d-cnn-for-regression/280/7 "2020-03-19T10:44:45Z")

</div>

thanks @treo it works
