android-demo-app icon indicating copy to clipboard operation
android-demo-app copied to clipboard

[ObjectDetection]: java.lang.IllegalStateException: Expected IValue type Tuple, actual type TensorList

Open lannguyen0910 opened this issue 3 years ago • 3 comments

Hi, when i used the Object Detection Demo, i encountered an IllegalStateException that expected IValue type to be Tuple, but actual type is TensorList. Here is the original code from MainActivity.java:

IValue[] outputTuple = mModule.forward(IValue.from(inputTensor)).toTuple();

final Tensor outputTensor = outputTuple[0].toTensor();

The error happens when i click the Detect button:

E/AndroidRuntime: FATAL EXCEPTION: Thread-2
    Process: com.lannguyen.food_detector, PID: 8115
    java.lang.IllegalStateException: Expected IValue type Tuple, actual type TensorList
        at org.pytorch.IValue.preconditionType(IValue.java:332)
        at org.pytorch.IValue.toTuple(IValue.java:313)
        at com.lannguyen.food_detector.MainActivity.run(MainActivity.java:238)
        at java.lang.Thread.run(Thread.java:923)

I've tried to modify using the TensorList type but the ArrayList results is empty:

Tensor[] outputTuple = mModule.forward(IValue.from(inputTensor)).toTensorList();

final Tensor outputTensor = outputTuple[0];

Also there is an unusual point that the mOutputRow in PrePostProcessor.java in my case doesn't have the original value 25200 but 19200 to not trigger any errors. The output tensor is [1,3, 80, 80 ,85] so i have to modify that value to 19200 instead 25200.

If you have any ideas to fix it, feel free to comment below. Thank you very much in advance!

lannguyen0910 avatar Dec 24 '21 12:12 lannguyen0910

I got same error...anyone can please assist...

Heena-S-Patel avatar May 09 '22 13:05 Heena-S-Patel

Has anyone solved above-mentioned error?

Heena-S-Patel avatar May 11 '22 07:05 Heena-S-Patel

have you solved above mentioned error? please update if you done it

Jagan3534 avatar Nov 05 '22 10:11 Jagan3534