deeplearning4j / deeplearning4j/deeplearning4j-examples

IndexOutOfBoundsException when importing onnx model

Open
#1,059 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.5k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

#### Issue Description

I follow the instruction from [deeplearning4j example](https://github.com/eclipse/deeplearning4j-examples/blob/master/onnx-import-examples/src/main/java/org/deeplearning4j/modelimportexamples/onnx/OnnxImportLoad.java) to load onnx model but I got this problem.

```
Exception in thread "main" java.lang.IndexOutOfBoundsException
at java.base/java.nio.Buffer.checkIndex(Buffer.java:749)
at java.base/java.nio.HeapByteBuffer.getInt(HeapByteBuffer.java:439)
at com.google.flatbuffers.Table.__reset(Table.java:301)
at org.nd4j.graph.FlatGraph.__init(FlatGraph.java:33)
at org.nd4j.graph.FlatGraph.__assign(FlatGraph.java:34)
at org.nd4j.graph.FlatGraph.getRootAsFlatGraph(FlatGraph.java:32)
at org.nd4j.graph.FlatGraph.getRootAsFlatGraph(FlatGraph.java:31)
at org.nd4j.autodiff.samediff.SameDiff.fromFlatBuffers(SameDiff.java:5458)
at org.nd4j.autodiff.samediff.SameDiff.fromFlatFile(SameDiff.java:5428)
at org.nd4j.autodiff.samediff.SameDiff.load(SameDiff.java:5319)
at it.rcpvision.dl4j.workbench.test_onnx.main(test_onnx.java:18)

```

My java code like this:
```
import org.nd4j.autodiff.samediff.SameDiff;
import org.nd4j.common.resources.Downloader;
import org.nd4j.samediff.frameworkimport.onnx.importer.OnnxFrameworkImporter;
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;

public class test_onnx {
public final static String MODEL_FILE_NAME = "super_resolution.onnx";

public static void main(String...args) throws Exception {
//load the imported model
SameDiff sameDiff = SameDiff.load(new File(MODEL_FILE_NAME),true);
//print the input names
System.out.println(sameDiff.inputs());
//print the shape of the input so we know what to feed the model
System.out.println(Arrays.toString(sameDiff.getVariable(sameDiff.inputs().get(0)).getShape()));

}
}
```

And the onnx model is built from: https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html

#### Version Information

* Deeplearning4j 1.0.0-M2
* MacOS M1 pro

Do you know the reason for this error ? Any suggestion is appreciated. Thank you in advance !

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.