Issue in getting 2d DataSet

Hi Team

While following a basic autoencoder tutorial(https://deeplearning4j.konduit.ai/getting-started/tutorials/basic-autoencoder), I am getting issue while evaluating score for testing sample at:

// testSample.getRow(j) - Vector of shape [1x784], used as input and target
model.score(new DataSet(testSample.getRow(j), testSample.getRow(j)))

Exception:
Exception in thread "main" org.deeplearning4j.exception.DL4JInvalidInputException: Input that is not a matrix; expected matrix (rank 2), got rank 1 array with shape [784]. Missing preprocessor or wrong input type? (layer name: layer0, layer index: 0, layer type: DenseLayer)

Please let me know if the whole code is required.
Please help!

Thanks & Regards

Think I can help with that as I had the identical error recently. DL4J expects the first dimension of your input to be batch size, so I think you need to transpose your input vector.

1 Like

Thank you for telling us about that bug in the Tutorials. Unfortunately, the tutorials are a bit out of date at the moment - so stumbling stones like this are going to happen every once in a while. I’ve updated the code in the tutorial to behave as needed at that point.

getRow now returns a simple vector, instead of a [1,n] matrix. But as the model always expects a matrix with the first dimension being the batch size, as @will-maclean has already noted, we need to get the old behavior in this case.

To get a matrix instead of a vector, you have to tell getRow to keep the leading dimension:

testSample.getRow(j, true)
1 Like

Hi @will-maclean and @treo,

Sorry for the late response, got busy last few weeks.

Thanks for clarifying the DL4J behaviour. And yes, that fixed the issue.
Also, unless helping persons like @treo are here, no one has to worry about the stumbling stones.

Thanks again!