mattn / go-tflite

Go binding for TensorFlow Lite
MIT License
304 stars 44 forks source link

How to 2D input inference #41

Closed meteoricfarm closed 3 years ago

meteoricfarm commented 3 years ago

Hello Everyone,

Thanks to your work, I could use the GO in my project. while I am using go-tflite, I have a question for input/output. My tflite input shape [4][3]float32 output shape [2][1]float32. How am I supposed to input and output properly?

Thanks for the reply in advance.


predict := []float32
for i := 0; i < num; i++ {
        inputs := [][]float32{}
        for j := 0; j < steps; j++ {
            inputs = append(inputs, data[j])
        }
        interpreter.GetInputTensor(0).CopyFromBuffer(inputs) // <<-- Error occurred here
        interpreter.Invoke()
        interpreter.GetOutputTensor(0).CopyToBuffer(predict)
        fmt.Println(predict)
    }

but it gave an error like below

panic: runtime error: cgo argument has Go pointer to Go pointer

mattn commented 3 years ago

CopyFromBuffer can not be handled slice of slice. It is NOT sequencial memory block. You can pass 1 dimensioned slice or array like ndarray.

Or you might be possible to use https://github.com/mattn/go-redimer

meteoricfarm commented 3 years ago

Hi, mattn

Thanks for the reply. I could obtain proper output following as you mentioned. And thanks again for this repo.

Sincerely,