deeplearning4j / deeplearning4j-examples

Deeplearning4j Examples (DL4J, DL4J Spark, DataVec)

Home Page:http://deeplearning4j.konduit.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IndexOutOfBoundsException when importing onnx model

DangTu97 opened this issue · comments

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 !