Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfBoundsException when importing onnx model #1059

Open
DangTu97 opened this issue Apr 22, 2022 · 0 comments
Open

IndexOutOfBoundsException when importing onnx model #1059

DangTu97 opened this issue Apr 22, 2022 · 0 comments

Comments

@DangTu97
Copy link

DangTu97 commented Apr 22, 2022

Issue Description

I follow the instruction from deeplearning4j example 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 !

@DangTu97 DangTu97 changed the title IndexOutOfBoundsException when importing IndexOutOfBoundsException when importing onnx model Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant