Expected Tuple but got String

KedirAli: <p><em>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</em></p>
<p>This is the code I had used</p>
<p>DetectButton.setOnClickListener(new View.OnClickListener() {</p>
<pre><code>        @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 &lt; score_arr.length; i++) {
                if (score_arr[i] &gt; 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);


        }
    });

}
</code></pre>
<p>The error messege:</p>
<p>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<br>
Exception raised from toTuple at …/…/…/…/src/main/cpp/libtorch_include/armeabi-v7a/ATen/core/ivalue_inl.h:931 (most recent call first):<br>
(no backtrace available)” failed<br>
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)</p>

KedirAli: <p>Thank you All those who read the error tried to figureout the error. I already fixed the problem by installing the same dependency.</p>

Robert_Grzelak: <p>Hello, I have somehow similar error. I try to make inference on RedisAI using exported torchscript yolov5 model, but got;</p>
<p>isTuple()INTERNAL ASSERT FAILED at “…/aten/src/ATen/core/ivalue_inl.h”:1916, <strong>please report a bug to PyTorch</strong>. Expected Tuple but got String Exception raised from toTupleRef at …/aten/src/ATen/core/ivalue_inl.h:1916 (most recent call first): frame <span class="hashtag-raw">#0:</span> c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt;) + 0x6b (0x7f02fbb747ab in /home/robb/Desktop/nn/RedisAI/deps/linux-x64-cpu/libtorch/lib/libc10.so) frame <span class="hashtag-raw">#1:</span> c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string&lt;char, std::char_traits,…</p>

KedirAli: <p>Can you share code snippet</p>
<p>Have you deployed the model on devices or you try the inference in python environment</p>

Robert_Grzelak: <p>Thank you for reply.</p>
<p>Sure, here it is;</p>
<pre><code class="lang-auto">from redisai import Client as rai
import numpy as np
import cv2

model_path = 'yolov5/runs/train/results_15/weights/best.torchscript'

# Connect to Redis
redis_client = rai(host='localhost', port=6379)

img = '/home/robb/Desktop/.../nn/YOLOv5_cars/yolov5/data/images/bus.jpg'
img = cv2.imread(img)
img = np.transpose(img, (2, 0, 1))
img = img[None, :].astype(np.float32) / 255.0  # adds batch size (1, 3, 1080, 810)


with open(model_path, 'rb') as f:
    model = f.read()


redis_client.modelstore('willitwork', 'torch', 'CPU', model)

redis_client.tensorset('my_tensor', img)

redis_client.modelexecute('willitwork', ['my_tensor'], ['output'])  # &lt;-- This line

output_tensor = redis_client.tensorget('output')
output_data = np.array(output_tensor)
</code></pre>
<p>I tried also with pt and onnx but modelstore method did not accepted these.</p>

sureshscribnar: <p>I have same issue. Which dependency did you install to fix the problem?</p>

minvo: <p>What was missing for you that you installed? Having the same issue</p>

Nburnett: <p>I fixed this by installing the latest pytorch android version 13.1<br>
<a href="https://mvnrepository.com/artifact/org.pytorch/pytorch_android" class="onebox" target="_blank" rel="noopener nofollow ugc">https://mvnrepository.com/artifact/org.pytorch/pytorch_android</a></p>

jose-solorzano: <p>What fixed this issue for me is to use <em>optimize_for_mobile</em> to transform the model before saving the script file.</p>