# CNN DataLoader::AddVariablesArray() for images with multi channels, order of input array

**URL:** <https://root-forum.cern.ch/t/cnn-dataloader-addvariablesarray-for-images-with-multi-channels-order-of-input-array/43709>\
**Category:** TMVA\
**Created:** [February 25, 2021, 6:01pm UTC](https://root-forum.cern.ch/t/cnn-dataloader-addvariablesarray-for-images-with-multi-channels-order-of-input-array/43709 "2021-02-25T18:01:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xinran\_Li](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xinran_li/32/19804_2.png) [@Xinran\_Li](https://root-forum.cern.ch/u/Xinran_Li)\
**Post date:** [February 25, 2021, 6:01pm UTC](https://root-forum.cern.ch/t/cnn-dataloader-addvariablesarray-for-images-with-multi-channels-order-of-input-array/43709/1 "2021-02-25T18:01:42Z")

</div>

Hi everyone,

I am trying to use the CNN in TMVA to analys pixelized electron track images.  
The images are 3D voxels of the track, with high resolution in XY and coarse resolution in Z. So I am treating the Z direction as the color channels in CNN. The images are 16x16x3 pixels in x,y and z.

The example [https://root.cern/doc/master/TMVA\_\_CNN\_\_Classification\_8C.html](https://root.cern/doc/master/TMVA __CNN__ Classification_8C.html) mentioned the possiblity to have multi-channel images as input with the `AddVariablesArray()` methode, and the inputLayout is  
`TString inputLayoutString("InputLayout=1|16|16");`  
For a 3 channel image, I modify the layout to `3|16|16` , but how should I order the pixels in the array? Should it be `vector<int> var[768]` with index `i_z*256 + i_y*16 +i_x` or `i_y*48 + i_x*3 +i_z` ?

Also I didn’t find the corresponding configuration for the layer layouts. Can I keep the same batch layout as in the tutorial example?

Thank you very much!  
Best regards  
Xinran

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [February 25, 2021, 8:01pm UTC](https://root-forum.cern.ch/t/cnn-dataloader-addvariablesarray-for-images-with-multi-channels-order-of-input-array/43709/2 "2021-02-25T20:01:30Z")

</div>

I think @moneta will be able to help you

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 1, 2021, 9:00am UTC](https://root-forum.cern.ch/t/cnn-dataloader-addvariablesarray-for-images-with-multi-channels-order-of-input-array/43709/3 "2021-03-01T09:00:14Z")

</div>

Hello,

The order in the array should be first the x,y pixel then the color channels,  
`i_z*256 + i_y*16 +i_x` in your case.

So following the tutorial you define:  
` TString inputLayoutString("InputLayout=3|16|16");`  
and then a layout string defining the convolutional layers and the following dense layers as in the tutorial.  
The batch layout staring should not be needed and you can just pass the batch size when you define the trainingString (see tutorial).  
If you have further questions, please let me know

Best

Lorenzo
