'How to feed and retrieve data from an ML model in android?
I am creating an android application using a machine learning model. I have a float array which contains only 0 and 1 [array = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, ....}]. Now this array is to be given to the model to get the result. The model returns float array as result. I am using following code to achieve the target but it returns this as a result [fl967ed4].
try {
MobileModel model = MobileModel.newInstance(getApplicationContext());
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 1, 215},
DataType.FLOAT32);
byte[] bytes = floatsToBytes(array);
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
inputFeature0.loadBuffer(byteBuffer);
// Runs model inference and gets result.
MobileModel.Outputs outputs = model.process(inputFeature0);
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
float[] data=outputFeature0.getFloatArray();
// Releases model resources if no longer used.
model.close();
return data[0];
} catch (IOException e) {
// TODO Handle the exception
}
Where am I doing wrong? Can anyone help me with this? any help will be appreciated. Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
