go-tflite
go-tflite copied to clipboard
Add object detection example
It would be useful to include an object detection example ( ie where the result is an image with boxes highlighing detected objects ).
Did you see example directory?
Did you see example directory?
Yes ... but I didn't see an "object detection" example - ie returns bounding box(s) from an image as well as label(s).
label_image, for example, is "image classification" - returns only a label.
Maybe look at one of these models https://coral.ai/models/object-detection/ ?
Mind you I didn't manage to get all the example running - eg label_image_xnnpack requires tensorflowlite-delegate_xnnpack which I've yet to figure out how to build.
What about ssd ?
https://user-images.githubusercontent.com/10111/200126310-98cb6ea0-903a-496b-9f52-c217d6de22ba.mp4
What about ssd ?
Ah, good point, thanks. I didn't look at that since its a web cam example.
I can see if I can convert it to single jpeg image or mp4 video.
Just realiased that the opencv gocv.OpenVideoCapture() will also read a file. So ssd example can be used something like :
go run main.go --camera image.1541392117.MP4
Output needs to be sent to a file as well ( so instead of gocv.NewWindow() use gocv.VideoWriterFile() ).
So this works well on my desktop (mac arm64) but I usually get a segv on my SBC (linux arm64)
Could you please share the stacktrace of SEGV ?
Sure. So testing a slightly modified ssd I sometimes see -
$ bash -x run.sh
+ export CGO_CFLAGS=-I/home/plord/src/tensorflow/tensorflow_src
+ CGO_CFLAGS=-I/home/plord/src/tensorflow/tensorflow_src
+ export CGO_LDFLAGS=-L/home/plord/src/tensorflow/tflite_build
+ CGO_LDFLAGS=-L/home/plord/src/tensorflow/tflite_build
+ export LD_LIBRARY_PATH=:/home/plord/src/tensorflow/tflite_build
+ LD_LIBRARY_PATH=:/home/plord/src/tensorflow/tflite_build
+ go build -o main main.go
+ ulimit -c unlimited
+ export GOTRACEBACK=2
+ GOTRACEBACK=2
+ ./main --camera image.1541392117.MP4
2022/11/08 08:20:44 width: 300, height: 300, type: UInt8, scale: 0.0078125, zeropoint: 128
2022/11/08 08:20:44 input tensor count: 1, output tensor count: 4
run.sh: line 12: 6383 Segmentation fault (core dumped) ./main --camera image.1541392117.MP4
gdb reports -
(gdb) thread apply all bt
Thread 21 (Thread 0xffff7d1309c0 (LWP 6386)):
#0 0x0000ffffad7eb97c in x264_8_pixel_var_16x16_neon () from /lib/aarch64-linux-gnu/libx264.so.160
#1 0x0000ffffad73ec3c in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffad740b24 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#3 0x0000ffffad764ed4 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#4 0x0000ffffb3429c28 in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#5 0x0000ffffb320e174 in avcodec_encode_video2 () from /lib/aarch64-linux-gnu/libavcodec.so.58
#6 0x0000ffffb320e4a4 in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#7 0x0000ffffb320e644 in avcodec_send_frame () from /lib/aarch64-linux-gnu/libavcodec.so.58
#8 0x0000ffffb6388838 in ?? () from /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#9 0x0000ffffb638a25c in ?? () from /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#10 0x0000ffffb638a4fc in ?? () from /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#11 0x0000ffffb634f3e4 in cv::VideoWriter::write(cv::_InputArray const&) () from /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#12 0x0000ffffb634e998 in cv::VideoWriter::operator<<(cv::Mat const&) () from /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#13 0x00000000004e124c in _cgo_25ff2424b939_Cfunc_VideoWriter_Write ()
#14 0x0000000000481b4c in runtime.asmcgocall () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:973
#15 0x00000040000021a0 in ?? ()
Backtrace stopped: not enough registers or memory available to unwind further
Thread 20 (Thread 0xffff54ff09c0 (LWP 6399)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad76942c in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 19 (Thread 0xffff67ffd9c0 (LWP 6389)):
#0 0x0000ffffb32778fc in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#1 0x0000ffffb327a4fc in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#2 0x0000ffffb32b86a8 in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#3 0x0000ffffb32b972c in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#4 0x0000ffffb32c0aac in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#5 0x0000ffffb35295ac in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#6 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#7 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 18 (Thread 0xffff51b7f9c0 (LWP 6400)):
#0 0x0000ffffb654eb10 in gemmlowp::NEON_64bit_GEMM_Int8Operands_LhsNonzero::Run(int*, unsigned long, unsigned long, unsigned char const*, unsigned char const*, unsigned long, unsigned long) const () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#1 0x0000ffffb65cfe2c in gemmlowp::GemmWithPackedRhsTask<gemmlowp::KernelFormat<gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1>, gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1> >, unsigned char, unsigned char, gemmlowp::BitDepthParams<gemmlowp::OperandRange<1, 255>, gemmlowp::OperandRange<0, 255> >, (gemmlowp::MapOrder)1, (gemmlowp::MapOrder)0, (gemmlowp::MapOrder)1, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8>, gemmlowp::GemmContext>::Run() () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#2 0x0000ffffb6509764 in gemmlowp::Worker::ThreadFunc(void*) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#3 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#4 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 17 (Thread 0xffff63ee29c0 (LWP 6396)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad7698b0 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 16 (Thread 0xffff667fa9c0 (LWP 6392)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffb35296ac in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 15 (Thread 0xffff7d9319c0 (LWP 6387)):
#0 0x0000ffffb654ec70 in gemmlowp::NEON_64bit_GEMM_Int8Operands_LhsNonzero::Run(int*, unsigned long, unsigned long, unsigned char const*, unsigned char const*, unsigned long, unsigned long) const () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#1 0x0000ffffb65cfe2c in gemmlowp::GemmWithPackedRhsTask<gemmlowp::KernelFormat<gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1>, gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1> >, unsigned char, unsigned char, gemmlowp::BitDepthParams<gemmlowp::OperandRange<1, 255>, gemmlowp::OperandRange<0, 255> >, (gemmlowp::MapOrder)1, (gemmlowp::MapOrder)0, (gemmlowp::MapOrder)1, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8>, gemmlowp::GemmContext>::Run() () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#2 0x0000ffffb655080c in gemmlowp::WorkersPool::LegacyExecuteAndDestroyTasks(std::vector<gemmlowp::Task*, std::allocator<gemmlowp::Task*> > const&) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#3 0x0000ffffb65d13a4 in void gemmlowp::MultiThreadGemm<gemmlowp::KernelFormat<gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1>, gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1> >, unsigned char, unsigned char, gemmlowp::BitDepthParams<gemmlowp::OperandRange<1, 255>, gemmlowp::OperandRange<0, 255> >, (gemmlowp::MapOrder)1, (gemmlowp::MapOrder)0, (gemmlowp::MapOrder)1, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8>, gemmlowp::GemmContext>(gemmlowp::GemmContext*, gemmlowp::KernelBase const&, gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1> const&, gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0> const&, gemmlowp::MatrixMap<unsigned char, (gemmlowp::MapOrder)1>*, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1> const&, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0> const&, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8> const&) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#4 0x0000ffffb65d307c in void gemmlowp::DispatchGemmShape<unsigned char, unsigned char, gemmlowp::BitDepthParams<gemmlowp::OperandRange<1, 255>, gemmlowp::OperandRange<0, 255> >, (gemmlowp::MapOrder)1, (gemmlowp::MapOrder)0, (gemmlowp::MapOrder)0, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)0> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8>, gemmlowp::GemmContext>(gemmlowp::GemmContext*, gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1> const&, gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0> const&, gemmlowp::MatrixMap<unsigned char, (gemmlowp::MapOrder)0>*, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0> const&, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1> const&, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)0> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8> const&) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#5 0x0000ffffb65f34c8 in void tflite::cpu_backend_gemm::Gemm<unsigned char, unsigned char, int, unsigned char, (tflite::cpu_backend_gemm::QuantizationFlavor)1>(tflite::cpu_backend_gemm::MatrixParams<unsigned char> const&, unsigned char const*, tflite::cpu_backend_gemm::MatrixParams<unsigned char> const&, unsigned char const*, tflite::cpu_backend_gemm::MatrixParams<unsigned char> const&, unsigned char*, tflite::cpu_backend_gemm::GemmParams<int, unsigned char, (tflite::cpu_backend_gemm::QuantizationFlavor)1> const&, tflite::CpuBackendContext*) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#6 0x0000ffffb65b68b0 in tflite::optimized_ops::Conv(tflite::ConvParams const&, tflite::RuntimeShape const&, unsigned char const*, tflite::RuntimeShape const&, unsigned char const*, tflite::RuntimeShape const&, int const*, tflite::RuntimeShape const&, unsigned char*, tflite::RuntimeShape const&, unsigned char*, tflite::CpuBackendContext*) [clone .isra.0] () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#7 0x0000ffffb65f5128 in void tflite::ops::builtin::conv::EvalQuantized<(tflite::ops::builtin::conv::KernelType)2>(TfLiteContext*, TfLiteNode*, TfLiteConvParams*, tflite::ops::builtin::conv::OpData*, TfLiteTensor const*, TfLiteTensor const*, TfLiteTensor const*, TfLiteTensor*, TfLiteTensor*) [clone .isra.0] () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#8 0x0000ffffb65f5800 in TfLiteStatus tflite::ops::builtin::conv::EvalImpl<(tflite::ops::builtin::conv::KernelType)2, (TfLiteType)3>(TfLiteContext*, TfLiteNode*) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#9 0x0000ffffb65f58c4 in TfLiteStatus tflite::ops::builtin::conv::Eval<(tflite::ops::builtin::conv::KernelType)2>(TfLiteContext*, TfLiteNode*) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#10 0x0000ffffb641617c in tflite::Subgraph::Invoke() () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#11 0x0000ffffb6421004 in tflite::Interpreter::Invoke() () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#12 0x0000ffffb6409994 in TfLiteInterpreterInvoke () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#13 0x00000000004d4bb4 in _cgo_7f4337267d2a_Cfunc_TfLiteInterpreterInvoke ()
#14 0x0000000000481b4c in runtime.asmcgocall () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:973
#15 0x0000004000082820 in ?? ()
Backtrace stopped: not enough registers or memory available to unwind further
Thread 14 (Thread 0xffff33ffd9c0 (LWP 6403)):
#0 runtime.futex () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:666
#1 0x000000000045057c in runtime.futexsleep (addr=<optimized out>, val=128, ns=0) at /usr/lib/go-1.19/src/runtime/os_linux.go:69
#2 0x000000000042b9f0 in runtime.notesleep (n=0x400003d148) at /usr/lib/go-1.19/src/runtime/lock_futex.go:160
#3 0x000000000045aa34 in runtime.mPark () at /usr/lib/go-1.19/src/runtime/proc.go:1457
#4 runtime.stopm () at /usr/lib/go-1.19/src/runtime/proc.go:2239
#5 0x000000000045c2ac in runtime.findRunnable (gp=<optimized out>, inheritTime=<optimized out>, tryWakeP=<optimized out>) at /usr/lib/go-1.19/src/runtime/proc.go:2866
#6 0x000000000045d2c8 in runtime.schedule () at /usr/lib/go-1.19/src/runtime/proc.go:3206
#7 0x0000000000459188 in runtime.mstart1 () at /usr/lib/go-1.19/src/runtime/proc.go:1432
#8 0x00000000004590a8 in runtime.mstart0 () at /usr/lib/go-1.19/src/runtime/proc.go:1382
#9 0x000000000047f640 in runtime.mstart () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:128
Thread 13 (Thread 0xffff646e39c0 (LWP 6395)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad7698b0 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 12 (Thread 0xffff656e59c0 (LWP 6393)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad7698b0 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 11 (Thread 0xffff66ffb9c0 (LWP 6391)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffb35296ac in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 10 (Thread 0xffff62ee09c0 (LWP 6398)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad7698b0 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 9 (Thread 0xffff64ee49c0 (LWP 6394)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad7698b0 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 8 (Thread 0xffff7c92f9c0 (LWP 6388)):
#0 runtime.futex () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:666
#1 0x000000000045057c in runtime.futexsleep (addr=<optimized out>, val=128, ns=0) at /usr/lib/go-1.19/src/runtime/os_linux.go:69
#2 0x000000000042b9f0 in runtime.notesleep (n=0x626a98 <runtime.newmHandoff+24>) at /usr/lib/go-1.19/src/runtime/lock_futex.go:160
#3 0x000000000045a920 in runtime.templateThread () at /usr/lib/go-1.19/src/runtime/proc.go:2217
#4 0x0000000000459158 in runtime.mstart1 () at /usr/lib/go-1.19/src/runtime/proc.go:1425
#5 0x00000000004590a8 in runtime.mstart0 () at /usr/lib/go-1.19/src/runtime/proc.go:1382
#6 0x000000000047f640 in runtime.mstart () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:128
Thread 7 (Thread 0xffff7e1729c0 (LWP 6385)):
#0 runtime.futex () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:666
#1 0x000000000045057c in runtime.futexsleep (addr=<optimized out>, val=128, ns=0) at /usr/lib/go-1.19/src/runtime/os_linux.go:69
#2 0x000000000042bbbc in runtime.notetsleep_internal (n=0x626be0 <runtime.sig>, ns=-1, ~r0=<optimized out>) at /usr/lib/go-1.19/src/runtime/lock_futex.go:183
#3 0x000000000042bca0 in runtime.notetsleepg (n=0x626be0 <runtime.sig>, ns=-1, ~r0=<optimized out>) at /usr/lib/go-1.19/src/runtime/lock_futex.go:237
#4 0x000000000047e6c0 in os/signal.signal_recv (~r0=<optimized out>) at /usr/lib/go-1.19/src/runtime/sigqueue.go:152
#5 0x00000000004cd61c in os/signal.loop () at /usr/lib/go-1.19/src/os/signal/signal_unix.go:23
#6 0x0000000000481d24 in runtime.goexit () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:1172
Thread 6 (Thread 0xffff636e19c0 (LWP 6397)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffad7698b0 in ?? () from /lib/aarch64-linux-gnu/libx264.so.160
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 5 (Thread 0xffffa5e40010 (LWP 6383)):
#0 runtime.futex () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:666
#1 0x000000000045057c in runtime.futexsleep (addr=<optimized out>, val=128, ns=0) at /usr/lib/go-1.19/src/runtime/os_linux.go:69
#2 0x000000000042b9f0 in runtime.notesleep (n=0x5f7928 <runtime.m0+328>) at /usr/lib/go-1.19/src/runtime/lock_futex.go:160
#3 0x0000000000459250 in runtime.mPark () at /usr/lib/go-1.19/src/runtime/proc.go:1457
#4 0x000000000045b300 in runtime.stoplockedm () at /usr/lib/go-1.19/src/runtime/proc.go:2440
#5 0x000000000045d254 in runtime.schedule () at /usr/lib/go-1.19/src/runtime/proc.go:3185
#6 0x000000000045d820 in runtime.park_m (gp=0x40000829c0) at /usr/lib/go-1.19/src/runtime/proc.go:3355
#7 0x000000000047f6b4 in runtime.mcall () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:192
#8 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 4 (Thread 0xffff677fc9c0 (LWP 6390)):
#0 0x0000ffffb5621414 in pthread_cond_wait@@GLIBC_2.17 () from /lib/aarch64-linux-gnu/libpthread.so.0
#1 0x0000ffffb35296ac in ?? () from /lib/aarch64-linux-gnu/libavcodec.so.58
#2 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#3 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 3 (Thread 0xffff50b7d9c0 (LWP 6402)):
#0 0x0000ffffb654ece8 in gemmlowp::NEON_64bit_GEMM_Int8Operands_LhsNonzero::Run(int*, unsigned long, unsigned long, unsigned char const*, unsigned char const*, unsigned long, unsigned long) const () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#1 0x0000ffffb65cfe2c in gemmlowp::GemmWithPackedRhsTask<gemmlowp::KernelFormat<gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1>, gemmlowp::KernelSideFormatInt8<gemmlowp::CellFormat<4, 16, (gemmlowp::CellOrder)1>, 1> >, unsigned char, unsigned char, gemmlowp::BitDepthParams<gemmlowp::OperandRange<1, 255>, gemmlowp::OperandRange<0, 255> >, (gemmlowp::MapOrder)1, (gemmlowp::MapOrder)0, (gemmlowp::MapOrder)1, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>, gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>, std::tuple<gemmlowp::OutputStageBiasAddition<gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1> >, gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8>, gemmlowp::GemmContext>::Run() () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#2 0x0000ffffb6509764 in gemmlowp::Worker::ThreadFunc(void*) () from /home/plord/src/tensorflow/tflite_build/libtensorflowlite_c.so
#3 0x0000ffffb561a648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#4 0x0000ffffb52c9c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
Thread 2 (Thread 0xffff7e9739c0 (LWP 6384)):
#0 runtime.usleep () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:143
#1 0x0000000000461ea8 in runtime.sysmon () at /usr/lib/go-1.19/src/runtime/proc.go:5145
#2 0x0000000000459158 in runtime.mstart1 () at /usr/lib/go-1.19/src/runtime/proc.go:1425
#3 0x00000000004590a8 in runtime.mstart0 () at /usr/lib/go-1.19/src/runtime/proc.go:1382
#4 0x000000000047f640 in runtime.mstart () at /usr/lib/go-1.19/src/runtime/asm_arm64.s:128
Thread 1 (Thread 0xffff5137e9c0 (LWP 6401)):
#0 runtime.raise () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:162
#1 0x000000000046a820 in runtime.raisebadsignal (sig=11, c=0xffff5137ca98) at /usr/lib/go-1.19/src/runtime/signal_unix.go:934
#2 0x000000000046aed8 in runtime.badsignal (sig=11, c=0xffff5137ca98) at /usr/lib/go-1.19/src/runtime/signal_unix.go:1054
#3 0x00000000004697cc in runtime.sigtrampgo (sig=11, info=0xffff5137cb70, ctx=0xffff5137cbf0) at /usr/lib/go-1.19/src/runtime/signal_unix.go:461
#4 0x0000000000482f48 in runtime.sigtramp () at /usr/lib/go-1.19/src/runtime/sys_linux_arm64.s:471
Without core dump, a further run gave -
$ bash -x run.sh
+ export CGO_CFLAGS=-I/home/plord/src/tensorflow/tensorflow_src
+ CGO_CFLAGS=-I/home/plord/src/tensorflow/tensorflow_src
+ export CGO_LDFLAGS=-L/home/plord/src/tensorflow/tflite_build
+ CGO_LDFLAGS=-L/home/plord/src/tensorflow/tflite_build
+ export LD_LIBRARY_PATH=:/home/plord/src/tensorflow/tflite_build
+ LD_LIBRARY_PATH=:/home/plord/src/tensorflow/tflite_build
+ export GOTRACEBACK=2
+ GOTRACEBACK=2
+ ulimit -c unlimited
+ ulimit -c 0
+ go run main.go --camera image.1541392117.MP4
2022/11/08 08:46:23 width: 300, height: 300, type: UInt8, scale: 0.0078125, zeropoint: 128
2022/11/08 08:46:23 input tensor count: 1, output tensor count: 4
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10ffff444ef0a0 pc=0xffff8be2fe2c]
runtime stack:
runtime.throw({0x523b6e?, 0xc400009000000074?})
/usr/lib/go-1.19/src/runtime/panic.go:1047 +0x40 fp=0xffff192df3c0 sp=0xffff192df390 pc=0x453e60
runtime.sigpanic()
/usr/lib/go-1.19/src/runtime/signal_unix.go:819 +0x1e4 fp=0xffff192df3f0 sp=0xffff192df3c0 pc=0x46a664
goroutine 4 [syscall]:
runtime.cgocall(0x4d4b8c, 0x40000b5d08)
/usr/lib/go-1.19/src/runtime/cgocall.go:158 +0x54 fp=0x40000b5cd0 sp=0x40000b5c90 pc=0x423f44
github.com/mattn/go-tflite._Cfunc_TfLiteInterpreterInvoke(0x172bdb70)
_cgo_gotypes.go:467 +0x38 fp=0x40000b5d00 sp=0x40000b5cd0 pc=0x4cdf18
github.com/mattn/go-tflite.(*Interpreter).Invoke.func1(0x172e2ec0?)
/home/plord/src/go-tflite/tflite.go:162 +0x50 fp=0x40000b5d40 sp=0x40000b5d00 pc=0x4ceef0
github.com/mattn/go-tflite.(*Interpreter).Invoke(0x40000b5ea8?)
/home/plord/src/go-tflite/tflite.go:162 +0x1c fp=0x40000b5d60 sp=0x40000b5d40 pc=0x4cee7c
main.detect({0x542d58, 0x4000188140}, 0x0?, 0x40000721e0, 0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/home/plord/src/go-tflite/_example/ssd/main.go:109 +0x360 fp=0x40000b5f70 sp=0x40000b5d60 pc=0x4d31a0
main.main.func8()
/home/plord/src/go-tflite/_example/ssd/main.go:188 +0x48 fp=0x40000b5fd0 sp=0x40000b5f70 pc=0x4d4348
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x40000b5fd0 sp=0x40000b5fd0 pc=0x481d24
created by main.main
/home/plord/src/go-tflite/_example/ssd/main.go:188 +0x470
goroutine 1 [syscall]:
runtime.cgocall(0x4e121c, 0x40000b1a58)
/usr/lib/go-1.19/src/runtime/cgocall.go:158 +0x54 fp=0x40000b1a20 sp=0x40000b19e0 pc=0x423f44
gocv.io/x/gocv._Cfunc_VideoWriter_Write(0x16fa79b0, 0xffff00008640)
_cgo_gotypes.go:7750 +0x34 fp=0x40000b1a50 sp=0x40000b1a20 pc=0x4d06a4
gocv.io/x/gocv.(*VideoWriter).Write.func1(0x2?, {0xffff00008640?, {0x0?, 0x2?, 0xffff3c000e50?}})
/home/plord/go/pkg/mod/gocv.io/x/[email protected]/videoio.go:469 +0x70 fp=0x40000b1a90 sp=0x40000b1a50 pc=0x4d2770
gocv.io/x/gocv.(*VideoWriter).Write(0x400004e470, {0xffff00008640?, {0x0?, 0x3?, 0x3?}})
/home/plord/go/pkg/mod/gocv.io/x/[email protected]/videoio.go:469 +0x90 fp=0x40000b1b20 sp=0x40000b1a90 pc=0x4d2680
main.main()
/home/plord/src/go-tflite/_example/ssd/main.go:248 +0x688 fp=0x40000b1f70 sp=0x40000b1b20 pc=0x4d3be8
runtime.main()
/usr/lib/go-1.19/src/runtime/proc.go:250 +0x254 fp=0x40000b1fd0 sp=0x40000b1f70 pc=0x456454
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x40000b1fd0 sp=0x40000b1fd0 pc=0x481d24
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/proc.go:363 +0xe4 fp=0x4000038fa0 sp=0x4000038f80 pc=0x456824
runtime.goparkunlock(...)
/usr/lib/go-1.19/src/runtime/proc.go:369
runtime.forcegchelper()
/usr/lib/go-1.19/src/runtime/proc.go:302 +0xb4 fp=0x4000038fd0 sp=0x4000038fa0 pc=0x4566b4
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x4000038fd0 sp=0x4000038fd0 pc=0x481d24
created by runtime.init.6
/usr/lib/go-1.19/src/runtime/proc.go:290 +0x24
goroutine 18 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/proc.go:363 +0xe4 fp=0x4000034770 sp=0x4000034750 pc=0x456824
runtime.goparkunlock(...)
/usr/lib/go-1.19/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
/usr/lib/go-1.19/src/runtime/mgcsweep.go:278 +0xa4 fp=0x40000347b0 sp=0x4000034770 pc=0x443be4
runtime.gcenable.func1()
/usr/lib/go-1.19/src/runtime/mgc.go:178 +0x28 fp=0x40000347d0 sp=0x40000347b0 pc=0x4382d8
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x40000347d0 sp=0x40000347d0 pc=0x481d24
created by runtime.gcenable
/usr/lib/go-1.19/src/runtime/mgc.go:178 +0x70
goroutine 19 [GC scavenge wait]:
runtime.gopark(0x400008e000?, 0x541dc8?, 0x1?, 0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/proc.go:363 +0xe4 fp=0x4000034f50 sp=0x4000034f30 pc=0x456824
runtime.goparkunlock(...)
/usr/lib/go-1.19/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x5f71a0)
/usr/lib/go-1.19/src/runtime/mgcscavenge.go:389 +0x5c fp=0x4000034f80 sp=0x4000034f50 pc=0x441bdc
runtime.bgscavenge(0x0?)
/usr/lib/go-1.19/src/runtime/mgcscavenge.go:617 +0x44 fp=0x4000034fb0 sp=0x4000034f80 pc=0x442144
runtime.gcenable.func2()
/usr/lib/go-1.19/src/runtime/mgc.go:179 +0x28 fp=0x4000034fd0 sp=0x4000034fb0 pc=0x438278
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x4000034fd0 sp=0x4000034fd0 pc=0x481d24
created by runtime.gcenable
/usr/lib/go-1.19/src/runtime/mgc.go:179 +0xb4
goroutine 3 [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/proc.go:363 +0xe4 fp=0x4000039580 sp=0x4000039560 pc=0x456824
runtime.goparkunlock(...)
/usr/lib/go-1.19/src/runtime/proc.go:369
runtime.runfinq()
/usr/lib/go-1.19/src/runtime/mfinal.go:180 +0x128 fp=0x40000397d0 sp=0x4000039580 pc=0x4374f8
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x40000397d0 sp=0x40000397d0 pc=0x481d24
created by runtime.createfing
/usr/lib/go-1.19/src/runtime/mfinal.go:157 +0x94
goroutine 5 [select, locked to thread]:
runtime.gopark(0x400003a7a0?, 0x2?, 0x0?, 0x0?, 0x400003a79c?)
/usr/lib/go-1.19/src/runtime/proc.go:363 +0xe4 fp=0x400003a630 sp=0x400003a610 pc=0x456824
runtime.selectgo(0x400003a7a0, 0x400003a798, 0x0?, 0x0, 0x0?, 0x1)
/usr/lib/go-1.19/src/runtime/select.go:328 +0x6b4 fp=0x400003a740 sp=0x400003a630 pc=0x466924
runtime.ensureSigM.func1()
/usr/lib/go-1.19/src/runtime/signal_unix.go:991 +0x1ac fp=0x400003a7d0 sp=0x400003a740 pc=0x46aa3c
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x400003a7d0 sp=0x400003a7d0 pc=0x481d24
created by runtime.ensureSigM
/usr/lib/go-1.19/src/runtime/signal_unix.go:974 +0xf4
goroutine 6 [syscall]:
runtime.notetsleepg(0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/lock_futex.go:236 +0x34 fp=0x400003af90 sp=0x400003af50 pc=0x42bc94
os/signal.signal_recv()
/usr/lib/go-1.19/src/runtime/sigqueue.go:152 +0x30 fp=0x400003afb0 sp=0x400003af90 pc=0x47e6c0
os/signal.loop()
/usr/lib/go-1.19/src/os/signal/signal_unix.go:23 +0x1c fp=0x400003afd0 sp=0x400003afb0 pc=0x4cd61c
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x400003afd0 sp=0x400003afd0 pc=0x481d24
created by os/signal.Notify.func1.1
/usr/lib/go-1.19/src/os/signal/signal.go:151 +0x2c
goroutine 7 [chan receive]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/proc.go:363 +0xe4 fp=0x400003b6e0 sp=0x400003b6c0 pc=0x456824
runtime.chanrecv(0x4000072240, 0x0, 0x1)
/usr/lib/go-1.19/src/runtime/chan.go:583 +0x47c fp=0x400003b770 sp=0x400003b6e0 pc=0x426cdc
runtime.chanrecv1(0x0?, 0x0?)
/usr/lib/go-1.19/src/runtime/chan.go:442 +0x14 fp=0x400003b7a0 sp=0x400003b770 pc=0x426824
main.main.func1()
/home/plord/src/go-tflite/_example/ssd/main.go:194 +0x2c fp=0x400003b7d0 sp=0x400003b7a0 pc=0x4d427c
runtime.goexit()
/usr/lib/go-1.19/src/runtime/asm_arm64.s:1172 +0x4 fp=0x400003b7d0 sp=0x400003b7d0 pc=0x481d24
created by main.main
/home/plord/src/go-tflite/_example/ssd/main.go:193 +0x548
exit status 2
Where the mention line in main.go is -
109 status := interpreter.Invoke()
110 if status != tflite.OK {
111 log.Println("invoke failed")
112 return
113 }
Could you please show me the diff ?
Sure ... this is what I've got ( hackish ... testing idea only ) -
diff --git a/_example/ssd/main.go b/_example/ssd/main.go
index 47a9e7d..914ba7e 100644
--- a/_example/ssd/main.go
+++ b/_example/ssd/main.go
@@ -12,7 +12,6 @@ import (
"os/signal"
"sort"
"sync"
- "time"
"github.com/mattn/go-tflite"
@@ -131,8 +130,8 @@ func main() {
}
// Setup Pixel window
- window := gocv.NewWindow("Webcam Window")
- defer window.Close()
+ //window := gocv.NewWindow("Webcam Window")
+ //defer window.Close()
ctx, cancel := context.WithCancel(context.Background())
@@ -143,10 +142,13 @@ func main() {
}
defer cam.Close()
- window.ResizeWindow(
- int(cam.Get(gocv.VideoCaptureFrameWidth)),
- int(cam.Get(gocv.VideoCaptureFrameHeight)),
- )
+ vw, err := gocv.VideoWriterFile("out.mp4", cam.CodecString(), cam.Get(gocv.VideoCaptureFPS), int(cam.Get(gocv.VideoCaptureFrameWidth)), int(cam.Get(gocv.VideoCaptureFrameHeight)), true)
+ defer vw.Close()
+
+ //window.ResizeWindow(
+ // int(cam.Get(gocv.VideoCaptureFrameWidth)),
+ // int(cam.Get(gocv.VideoCaptureFrameHeight)),
+ //)
model := tflite.NewModelFromFile(*modelPath)
if model == nil {
@@ -194,10 +196,10 @@ func main() {
}()
// Some local vars to calculate frame rate
- var (
- frames = 0
- second = time.Tick(time.Second)
- )
+ //var (
+ // frames = 0
+ // second = time.Tick(time.Second)
+ //)
for {
// Run inference if we have a new frame to read
@@ -235,33 +237,34 @@ func main() {
int(float32(size[0])*class.loc[0]),
int(float32(size[1])*class.loc[3]),
int(float32(size[0])*class.loc[2]),
- ), c, 2)
+ ), c, 4)
text := fmt.Sprintf("%d %.5f %s", i, class.score, label)
gocv.PutText(&result.mat, text, image.Pt(
int(float32(size[1])*class.loc[1]),
int(float32(size[0])*class.loc[0]),
- ), gocv.FontHersheySimplex, 1.2, c, 1)
+ ), gocv.FontHersheySimplex, 1.2, c, 4)
}
- window.IMShow(result.mat)
+ vw.Write(result.mat)
+ //window.IMShow(result.mat)
result.mat.Close()
- k := window.WaitKey(1)
- if k == 0x1b {
- break
- }
- if window.GetWindowProperty(gocv.WindowPropertyVisible) == 0 {
- break
- }
+ //k := window.WaitKey(1)
+ //if k == 0x1b {
+ // break
+ //}
+ //if window.GetWindowProperty(gocv.WindowPropertyVisible) == 0 {
+ // break
+ //}
// calculate frame rate
- frames++
- select {
- case <-second:
- window.SetWindowTitle(fmt.Sprintf("SSD | FPS: %d", frames))
- frames = 0
- default:
- }
+ //frames++
+ //select {
+ //case <-second:
+ // window.SetWindowTitle(fmt.Sprintf("SSD | FPS: %d", frames))
+ // frames = 0
+ //default:
+ //}
}
cancel()
I think I mentioned this already, but on the SBC it sometimes works but mostly segv's. On my desktop mac ( also arm ) is works consistently.
I wonder that boundary of the slice which is defined your model file is matched.
I re-built tensorflow locally ... this time used 2.5.3 rather than the latest. So far no SEGV.