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

panic: index out of range #208

Open
yg7001 opened this issue Jul 4, 2023 · 4 comments
Open

panic: index out of range #208

yg7001 opened this issue Jul 4, 2023 · 4 comments

Comments

@yg7001
Copy link

yg7001 commented Jul 4, 2023

func getONNXInputSize(onnxFilePath string) {
	backend:=simple.NewSimpleGraph()
	//backend:=gorgonnx.NewGraph()
	model  := onnx.NewModel(backend)	
	// read the onnx model
	b, err := utils.LoadFileBytes(onnxFilePath)
	if err!=nil{
		fmt.Println("read file error ",onnxFilePath,err)
		panic(err)
	}
	if len(b)==0{
		fmt.Println("onnf file error with lenght 0")
	}
	// Decode it into the model
	err = model.UnmarshalBinary(b)   // panic goes here!!!!!!!!!!!!!!!!!!!!!!!!
	if err!=nil{
		fmt.Println("parse onnx failure",err)
		panic(err)
	}
	inputs := model.GetInputTensors()
	if len(inputs) == 0 {
		fmt.Println("No inputs found in the ONNX model")
	}
	input := inputs[0]

	dims := input.Dims()
	fmt.Println("Input image dimensions:", dims)
}

output:
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
gorgonia.org/tensor.StdEng.makeArray({{}}, 0xc00015adb8, {{0x831c20?, 0x721f60?}}, 0x0)
D:/golangdev/work/pkg/mod/gorgonia.org/tensor@v0.9.3/defaultengine.go:22 +0xec
gorgonia.org/tensor.(*Dense).makeArray(0xc00015ad80, 0x0)
D:/golangdev/work/pkg/mod/gorgonia.org/tensor@v0.9.3/dense.go:87 +0xe2
gorgonia.org/tensor.(*Dense).fix(0xc00015ad80)
D:/golangdev/work/pkg/mod/gorgonia.org/tensor@v0.9.3/dense.go:292 +0x1c5
gorgonia.org/tensor.New({0xc001cb4920, 0x3, 0x1?})
D:/golangdev/work/pkg/mod/gorgonia.org/tensor@v0.9.3/tensor.go:93 +0xb8
github.com/owulveryck/onnx-go/internal/onnx/ir.(*TensorProto).Tensor(0xc000141e60)
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/internal/onnx/ir/tensor.go:51 +0x5e5
github.com/owulveryck/onnx-go.toOperationAttribute(0xc0000c6100)
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/attributes.go:30 +0x109
github.com/owulveryck/onnx-go.toOperationAttributes({0xc00000a710, 0x1, 0xc0000afbf0?})
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/attributes.go:10 +0x6c
github.com/owulveryck/onnx-go.(*Model).applyModelProtoGraphNodeOperations(0xc00010bce0, 0xc000100500?)
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/decoder.go:235 +0x10d
github.com/owulveryck/onnx-go.(*Model).applyModelProtoGraph(0xc00010bce0, 0xc000132210)
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/decoder.go:149 +0x299
github.com/owulveryck/onnx-go.(*Model).decodeProto(0xc000198000?, 0x1b0853b?)
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/decoder.go:112 +0x105
github.com/owulveryck/onnx-go.(*Model).UnmarshalBinary(0x7a3222?, {0xc000198000, 0x1b0853b, 0x1b0853c})
D:/golangdev/work/pkg/mod/github.com/owulveryck/onnx-go@v0.5.0/decoder.go:38 +0x75
main.getONNXInputSize({0x7a3222, 0x24})
D:/GolangDev/learnings/testGoCV/yolov3.go:256 +0x277
main.testYolo()
D:/GolangDev/learnings/testGoCV/yolov3.go:27 +0x3a
main.main()
D:/GolangDev/learnings/testGoCV/main.go:27 +0x17
exit status 2

@annatelegina
Copy link

Hello! I have the same error, have you found the solution? I can not identify where the problem is.

@BerndCzech
Copy link

I am running into the same issue - I guess 209 is just a copy of it.

@BerndCzech
Copy link

I found 184 also ran into the issue. As this is long ago with no solution i guess there is no known fix to it.

@BerndCzech
Copy link

BerndCzech commented Jul 16, 2023

It might help to know that s is of length 0 in /home/bernd/go/pkg/mod/gorgonia.org/tensor@v0.9.3/defaultengine.go:16:

func (e StdEng) makeArray(arr *array, t Dtype, size int) {
	memsize := calcMemSize(t, size)
	s := make([]byte, memsize)
	arr.t = t
	arr.L = size
	arr.C = size
	arr.Ptr = unsafe.Pointer(&s[0])
	arr.fix()
}

So this is why s[0] panics.

The depending project knows of the issue from tests but seems to regard this as an artifact. Thus I presume onnx-go should avoid calling their api with size = 0.

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

3 participants