java.lang.ArrayIndexOutOfBoundsException: vector

Hello everyone,

I’ve been trying to load a model that accept 2 images as input source and passed as a list. I got this error:

Process: org.pytorch.demo.imagesegmentation, PID: 10778
    java.lang.ArrayIndexOutOfBoundsException: vector
        at org.pytorch.LiteNativePeer.forward(Native Method)
        at org.pytorch.Module.forward(Module.java:52)
        at org.pytorch.imagesegmentation.MainActivity.run(MainActivity.java:140)

Code to load model:

I tried this one;

Map<String, IValue> outTensors = mModule.forward(
                IValue.tupleFrom(
                        IValue.from(inputTensor),
                        IValue.from(inputTensor2)
                )
        ).toDictStringKey();

and this

IValue img = IValue.listFrom(inputTensor, inputTensor2);
final Tensor outputTensor = mModule.forward(img).toTensor();

Please, someone could help me?

1 Like

Separate “forward” and “toTensor/toDictStringKey” statements so you can better identify the issue. If still not resolved, please paste the complete inference code here.

1 Like

As I’m facing a very similar problem, and have tried similar solutions to no avail, I’d be interested to know if anybody can produce a minimal working example of forward() with more than one input, including the ‘example_inputs’ used in the torch.jit.script() command used to export the model.
I’m using pytorch 1.10.2 and pytorch_android_lite:1.10.0

Hi @JoshGreifer

I got run my code with success when I used like it:

final Tensor outputTuple = mModule.forward(IValue.from(inputTensor), IValue.from(inputTensor2)).toTensor();

1 Like

I guess the reason is the model accepts 2 input, but you originally use one input or one list with 2 items to the model.