pytorch / android-demo-app

PyTorch android examples of usage in applications
1.46k stars 604 forks source link

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

Open lannguyen0910 opened 2 years ago

lannguyen0910 commented 2 years ago

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!

Heena-S-Patel commented 2 years ago

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

Heena-S-Patel commented 2 years ago

Has anyone solved above-mentioned error?

Jagan3534 commented 1 year ago

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