Deeplearning4j: NativeImageLoader returns null when converting from Mat

Created on 26 Jun 2018  路  3Comments  路  Source: eclipse/deeplearning4j

I'm currently trying to convert Mat images to INDArray as follows :

//Load image file
Mat srcImage = Imgcodecs.imread(args[0]);

//Rescale
Mat cvImage = new Mat(64,64,srcImage.type());
Imgproc.resize(srcImage,cvImage,cvImage.size(),0,0,Imgproc.INTER_CUBIC);

NativeImageLoader loader = new NativeImageLoader(64,64,1);
INDArray image = loader.asMatrix(cvImage);

MultiLayerNetwork model = KerasModelImport.importKerasSequentialModelAndWeights(args[1], false);
model.predict(image);

However, the INDArray image return null when loading either srcImage or its scaled down cvImage. Both Mat return non-null value and displays correct images when saved.

DataVec / ETL Question

All 3 comments

NativeImageLoader doesn't support that Mat object, use the one given in the docs:
https://deeplearning4j.org/datavecdoc/org/datavec/image/loader/NativeImageLoader.html#asMatrix-org.bytedeco.javacpp.opencv_core.Mat-

Changing the Mat package from org.opencv to org.bytedeco.javacpp.opencv_core ones resolves the problem as said. Thank you!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taraliza picture taraliza  路  6Comments

Storm-cev picture Storm-cev  路  5Comments

AlexDBlack picture AlexDBlack  路  4Comments

sshepel picture sshepel  路  4Comments

hanbaoan123 picture hanbaoan123  路  4Comments