Does go-tflite supports string tensors?
I only see SetFloat32s function. We have a converted model that accepts floats, strings and stringlists as input.
interpreter.AllocateTensors()
input := interpreter.GetInputTensor(0)
input.SetFloat32s([]float32{0.5})
Probably, you might mean DynamicBuffer.
@mattn are there any examples on how to create tensors with string or lists of string ? thanks!
See _example/smartreply.
https://github.com/mattn/go-tflite/blob/edc319170065164c7fc204b7cf847a8c8af2cea5/_example/smartreply/main.go#L33-L38
@mattn do you think is this related to the fact I'm using macOS arm64?
tfliteModel := tflite.NewModelFromFile("model.tflite")
interpreter := tflite.NewInterpreter(tfliteModel, nil)
var dbuf = new(tflite.DynamicBuffer)
dbuf.AddString("demo")
dbuf.WriteToTensorAsVector(interpreter.GetInputTensor(37))
# demo.com
ld: warning: dylib (/usr/local/lib/libtensorflowlite_c.so) was built for newer macOS version (13.1) than being linked (12.0)
/private/var/folders/7m/mnymf5ss1mz39ygdshyl69n40000gp/T/GoLand/___1go_build_demo_com
SIGTRAP: trace trap
PC=0x1a4040bb0 m=0 sigcode=0
signal arrived during cgo execution
goroutine 1 [syscall]:
runtime.cgocall(0x104a16544, 0x14000054c08)
/usr/local/go/src/runtime/cgocall.go:157 +0x44 fp=0x14000054bd0 sp=0x14000054b90 pc=0x10495dbb4
github.com/mattn/go-tflite._Cfunc_writeToTensorAsVector(0x158099030, 0x1400011a0c0, 0x10, 0x1)
_cgo_gotypes.go:821 +0x30 fp=0x14000054c00 sp=0x14000054bd0 pc=0x1049fe280
github.com/mattn/go-tflite.(*DynamicBuffer).WriteToTensorAsVector.func1(0x104a65568?, {0x1400011a0c0, 0x10, 0x1400012c000?}, 0x0?)
/Users/juan.crescente/go/pkg/mod/github.com/mattn/[email protected]/tflite_experimental.go:371 +0x78 fp=0x14000054c40 sp=0x14000054c00 pc=0x1049fedf8
github.com/mattn/go-tflite.(*DynamicBuffer).WriteToTensorAsVector(0x1400012c000, 0x104a17250?)
/Users/juan.crescente/go/pkg/mod/github.com/mattn/[email protected]/tflite_experimental.go:371 +0xf0 fp=0x14000054cb0 sp=0x14000054c40 pc=0x1049fece0
main.main()
/Users/juan.crescente/Documents/code/go_train/tflite/main.go:16 +0x74 fp=0x14000054f30 sp=0x14000054cb0 pc=0x104a14a84
runtime.main()
/usr/local/go/src/runtime/proc.go:267 +0x2bc fp=0x14000054fd0 sp=0x14000054f30 pc=0x10498e5ac
runtime.goexit()
/usr/local/go/src/runtime/asm_arm64.s:1197 +0x4 fp=0x14000054fd0 sp=0x14000054fd0 pc=0x1049ba9a4
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:398 +0xc8 fp=0x14000044f90 sp=0x14000044f70 pc=0x10498e9d8
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:404
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:322 +0xb8 fp=0x14000044fd0 sp=0x14000044f90 pc=0x10498e868
runtime.goexit()
/usr/local/go/src/runtime/asm_arm64.s:1197 +0x4 fp=0x14000044fd0 sp=0x14000044fd0 pc=0x1049ba9a4
created by runtime.init.6 in goroutine 1
/usr/local/go/src/runtime/proc.go:310 +0x24
goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:398 +0xc8 fp=0x14000045760 sp=0x14000045740 pc=0x10498e9d8
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:404
runtime.bgsweep(0x0?)
/usr/local/go/src/runtime/mgcsweep.go:280 +0xa0 fp=0x140000457b0 sp=0x14000045760 pc=0x10497bc80
runtime.gcenable.func1()
/usr/local/go/src/runtime/mgc.go:200 +0x28 fp=0x140000457d0 sp=0x140000457b0 pc=0x1049709d8
runtime.goexit()
/usr/local/go/src/runtime/asm_arm64.s:1197 +0x4 fp=0x140000457d0 sp=0x140000457d0 pc=0x1049ba9a4
created by runtime.gcenable in goroutine 1
/usr/local/go/src/runtime/mgc.go:200 +0x6c
goroutine 18 [GC scavenge wait]:
runtime.gopark(0x1400006e000?, 0x104a3dde0?, 0x1?, 0x0?, 0x14000082340?)
/usr/local/go/src/runtime/proc.go:398 +0xc8 fp=0x14000040750 sp=0x14000040730 pc=0x10498e9d8
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:404
runtime.(*scavengerState).park(0x104af97e0)
/usr/local/go/src/runtime/mgcscavenge.go:425 +0x5c fp=0x14000040780 sp=0x14000040750 pc=0x1049794ec
runtime.bgscavenge(0x0?)
/usr/local/go/src/runtime/mgcscavenge.go:653 +0x44 fp=0x140000407b0 sp=0x14000040780 pc=0x104979a44
runtime.gcenable.func2()
/usr/local/go/src/runtime/mgc.go:201 +0x28 fp=0x140000407d0 sp=0x140000407b0 pc=0x104970978
runtime.goexit()
/usr/local/go/src/runtime/asm_arm64.s:1197 +0x4 fp=0x140000407d0 sp=0x140000407d0 pc=0x1049ba9a4
created by runtime.gcenable in goroutine 1
/usr/local/go/src/runtime/mgc.go:201 +0xac
goroutine 34 [finalizer wait]:
runtime.gopark(0x22?, 0x0?, 0xe8?, 0x45?, 0x1049df5cc?)
/usr/local/go/src/runtime/proc.go:398 +0xc8 fp=0x14000044580 sp=0x14000044560 pc=0x10498e9d8
runtime.runfinq()
/usr/local/go/src/runtime/mfinal.go:193 +0x108 fp=0x140000447d0 sp=0x14000044580 pc=0x10496fac8
runtime.goexit()
/usr/local/go/src/runtime/asm_arm64.s:1197 +0x4 fp=0x140000447d0 sp=0x140000447d0 pc=0x1049ba9a4
created by runtime.createfing in goroutine 1
/usr/local/go/src/runtime/mfinal.go:163 +0x80
r0 0x0
r1 0x0
r2 0x0
r3 0x0
r4 0x0
r5 0x0
r6 0x0
r7 0x0
r8 0x314a1986e7dd00f4
r9 0x314a1986e7dd00f4
r10 0x1e000000
r11 0x1
r12 0x16b4a7262
r13 0x0
r14 0x104b34d8b
r15 0x54
r16 0xfffffffffffffff4
r17 0x1fe237ef8
r18 0x0
r19 0x600002bb6ce0
r20 0x1
r21 0x158099030
r22 0x1400011a0c0
r23 0x10
r24 0x0
r25 0x0
r26 0x14000054b00
r27 0x848
r28 0x104af9880
r29 0x16b4a7460
lr 0x456d0001a4040bb0
sp 0x16b4a7460
pc 0x1a4040bb0
fault 0x1a4040bb0
Process finished with the exit code 2
Can you provide simplest code to do same in Python ?