I had converted PyTorch model to torch script which uses image and meta-data. When I tried to deploy on android, get the above Error. I am expecting someone who can suggest the cause of the error and the possible solution
This is the code I had used
DetectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
int Moisture = Integer.parseInt(txt.getText().toString());
String odor = ked.getSelectedItem().toString();
String insects = ked1.getSelectedItem().toString();
int[] meta = new int[5];
if (insects == "Yes") {
meta [0] = 1;
} else {
meta [1] = 1;
}
meta [2] = Moisture;
if (odor == "Yes") {
meta [3] = 1;
} else {
meta [4] = 1;
}
Bitmap bitmap = null;
Module module = null;
//Getting the image from the image view
ImageView imageView = (ImageView) findViewById(R.id.image);
try {
//Read the image as Bitmap
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
//Here we reshape the image into 400*400
bitmap = Bitmap.createScaledBitmap(bitmap, 224, 224, true);
//Loading the model file.
module = Module.load(fetchModelFile(NewActivity.this, "sub.pt"));
} catch (IOException e) {
finish();
}
//Input Tensor
Tensor input2 = Tensor.fromBlob(meta, new long[]{1, meta.length});
Tensor input1 = TensorImageUtils.bitmapToFloat32Tensor(
bitmap,
TensorImageUtils.TORCHVISION_NORM_MEAN_RGB,
TensorImageUtils.TORCHVISION_NORM_STD_RGB
);
//Calling the forward of the model to run our input
assert module != null;
final Tensor output = module.forward(IValue.from(input1), IValue.from(input2)).toTensor();
final float[] score_arr = output.getDataAsFloatArray();
// Fetch the index of the value with maximum score
float max_score = -Float.MAX_VALUE;
int ms_ix = -1;
for (int i = 0; i < score_arr.length; i++) {
if (score_arr[i] > max_score) {
max_score = score_arr[i];
ms_ix = i;
}
}
//Fetching the name from the list based on the index
String detected_class = MODELCLASSES.MODEL_CLASSES[ms_ix];
//Writing the detected class in to the text view of the layout
TextView textView = findViewById(R.id.result_text);
textView.setText(detected_class);
}
});
}
The error messege:
2023-05-08 01:13:08.000 2549-2549/com.example.skinn A/libc: /buildbot/src/android/ndk-release-r21/external/libcxx/…/…/external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion “terminating with uncaught exception of type c10::Error: isTuple() INTERNAL ASSERT FAILED at “…/…/…/…/src/main/cpp/libtorch_include/armeabi-v7a/ATen/core/ivalue_inl.h”:931, please report a bug to PyTorch. Expected Tuple but got String
Exception raised from toTuple at …/…/…/…/src/main/cpp/libtorch_include/armeabi-v7a/ATen/core/ivalue_inl.h:931 (most recent call first):
(no backtrace available)” failed
2023-05-08 01:13:08.001 2549-2549/com.example.skinn A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 2549 (m.example.skinn), pid 2549 (m.example.skinn)