How to add multiple inputs with MultiDataSetIterator + Computation Graph?

This seems like it should be simple but I haven’t seen any examples and my attempts are not working.

Suppose I have an input CSV file with 7 columns. The first six columns are ordinary numerical data but the final column is categorical. It seems the way to handle this would be something like this

MultiDataSetIterator mdsi = new RecordReaderMultiDataSetIterator.Builder(batchSize)
                                             .addReader("csvData", csvInputReader)
                                             .addInput("csvData", 0, 5)
                                             .addInputOneHot("csvData", 6, numClasses)
                                             .
                                             . //add reader for labels, output layer, etc
                                             .
                                             .build();

and then in setting up the ComputeGraph

ComputationGraphConfiguration cgc = new NeuralNetConfiguration.Builder()
                                                              .updater(new Sdg(1e-3))
                                                              .graphBuilder()
                                                              .addInputs("input0", "input1")
                                                              .addLayer("I0", new DenseLayer. Builder()
                                                                  .nIn(inputSize)
                                                                  .nOut(layer1Size)
                                                                  .weightInit(WeightInit.ZERO)
                                                                 .activation(Activation.SIGMOID)
                                                                 .build(), "input0")
                                                              .addLayer("I1", new DenseLayer. Builder()
                                                                  .nIn(inputSize)
                                                                  .nOut(layer1Size)
                                                                  .weightInit(WeightInit.ZERO)
                                                                 .activation(Activation.SIGMOID)
                                                                 .build(), "input1")
                                                             .addVertex("merge", new MergeVertex(), "I0", "I1")
                                                              .
                                                              .//add layers etc
                                                              .
                                                              .build();

Doing this will get me the error: Invalid input for layer (layer name = “I1”): input type is null

I thought I was adhering tot he closest example I could find from https://deeplearning4j.konduit.ai/models/computationgraph but what is wrong with my code here?

This might sound dumb but I had the same error and found that there was a comma value before my “\n” in the csv file and I didn’t notice it because it just shows up as a blank cell when visually inspecting the data in a spreadsheet.

1 Like

Interesting! I just checked and there is no such issue with my data file though.

in my case it came from a line I left out of the example. the last two lines of my compute graph config looked like this

.setInputTypes(InputType.feedForward(batchSize))
.build();

Adding an additional input I had to make it look like this

.setInputTypes(InputType.feedForward(batchSize), InputType.feedForward(batchSize))
.build();

Apparently it was trying to match input types to the inputs and when it only found one it set the second to null.