I guess the error comes from the line
INDArray image = img.put(1,img);
And you are doing it because you had an error similar to Wrong input size - expected matrix - #3 by will-maclean?
Use asMatrix instead of asRowVector and skip this put thing entirely.