TfLite micro中打印model 结构的方法
在tflite for micro中,提交了micro_optional_debug_tools.h/cc等文件用于得到类似如下的打印:
打印出的信息
Interpreter has 16 tensors and 7 nodes
Inputs: 1
Outputs: 0
Tensor 0 Identity kTfLiteFloat32 kTfLiteArenaRw 16 bytes ( 0.0 MB) 1 4
Tensor 1 conv2d_10_input kTfLiteFloat32 kTfLiteArenaRw 1536 bytes ( 0.0 MB) 1 128 3 1
Tensor 2 sequential_5/conv2d_10/Conv2D/ReadVariableOp kTfLiteFloat32 kTfLiteMmapRo 384 bytes ( 0.0 MB) 1 4 3 8
Tensor 3 sequential_5/conv2d_10/Conv2D_bias kTfLiteFloat32 kTfLiteMmapRo 32 bytes ( 0.0 MB) 8
Tensor 4 sequential_5/conv2d_10/Relu kTfLiteFloat32 kTfLiteArenaRw 12288 bytes ( 0.0 MB) 1 128 3 8
Tensor 5 sequential_5/conv2d_11/Conv2D/ReadVariableOp kTfLiteFloat32 kTfLiteMmapRo 2048 bytes ( 0.0 MB) 16 4 1 8
Tensor 6 sequential_5/conv2d_11/Conv2D_bias kTfLiteFloat32 kTfLiteMmapRo 64 bytes ( 0.0 MB) 16
Tensor 7 sequential_5/conv2d_11/Relu kTfLiteFloat32 kTfLiteArenaRw 2688 bytes ( 0.0 MB) 1 42 1 16
Tensor 8 sequential_5/dense_10/MatMul/ReadVariableOp/transpose kTfLiteFloat32 kTfLiteMmapRo 14336 bytes ( 0.0 MB) 16 224
Tensor 9 sequential_5/dense_10/MatMul_bias kTfLiteFloat32 kTfLiteMmapRo 64 bytes ( 0.0 MB) 16
Tensor 10 sequential_5/dense_10/Relu kTfLiteFloat32 kTfLiteArenaRw 64 bytes ( 0.0 MB) 1 16
Tensor 11 sequential_5/dense_11/BiasAdd kTfLiteFloat32 kTfLiteArenaRw 16 bytes ( 0.0 MB) 1 4
Tensor 12 sequential_5/dense_11/MatMul/ReadVariableOp/transpose kTfLiteFloat32 kTfLiteMmapRo 256 bytes ( 0.0 MB) 4 16
Tensor 13 sequential_5/dense_11/MatMul_bias kTfLiteFloat32 kTfLiteMmapRo 16 bytes ( 0.0 MB) 4
Tensor 14 sequential_5/max_pooling2d_10/MaxPool kTfLiteFloat32 kTfLiteArenaRw 1344 bytes ( 0.0 MB) 1 42 1 8
Tensor 15 sequential_5/max_pooling2d_11/MaxPool kTfLiteFloat32 kTfLiteArenaRw 896 bytes ( 0.0 MB) 1 14 1 16
Node 0 Operator Builtin Code 4 DEPTHWISE_CONV_2D
Inputs: 1 2 3
Outputs: 4
Node 1 Operator Builtin Code 17 MAX_POOL_2D
Inputs: 4
Outputs: 14
Node 2 Operator Builtin Code 3 CONV_2D
Inputs: 14 5 6
Outputs: 7
Node 3 Operator Builtin Code 17 MAX_POOL_2D
Inputs: 7
Outputs: 15
Node 4 Operator Builtin Code 9 FULLY_CONNECTED
Inputs: 15 8 9
Outputs: 10
Node 5 Operator Builtin Code 9 FULLY_CONNECTED
Inputs: 10 12 13
Outputs: 11
Node 6 Operator Builtin Code 25 SOFTMAX
Inputs: 11
Outputs: 0
但在今天的使用中出现了问题且是 core dump
这里先记下怎么正确使用:
引入头文件micro_optional_debug_tools.h
#include "tensorflow/lite/experimental/micro/micro_optional_debug_tools.h"
调用函数PrintInterpreterState
pInterpreter->AllocateTensors();
tflite::PrintInterpreterState(pInterpreter);
调用函数的顺序,一定要在AllocateTensors的后面,否则会出现coredump
怎样使用coredump
因长时间没有看相关代码,使用模型文件结构打印时把tflite::PrintInterpreterState(pInterpreter)放到了pInterpreter->AllocateTensors()的前面 ,导致的coredump。在问题解决的过程中,因为tflite micro的代码变化挺大,搞不清是自己的问题还是其他问题,所以这里引入coredump, 并记录coredump使用过程中的一些问题。
core dump保存到哪里
保存到哪里这个问题分两步,是否保存了?保存路径在?
是否生成
ulimit -c 看core dump文件设置的大小,如果
ulimit -c
0
则需要设置
ulimit -c unlimited (设置为无穷大,不会出现大小导致的问题)
另外需要注意,这里的设置不是全局变量,需要在要执行程序的shell中设置
生成路径
默认路径是和执行程序路径一致,默认的文件名是core
也可以设置固定路径(这里不关注)可参考
https://blog.51cto.com/xjsunjie/1954870
得到coredump后怎么使用
gdb gesture_recognition_test_binary core
gdb gesture_recognition_test_binary core
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from gesture_recognition_test_binary...(no debugging symbols found)...done.
warning: core file may not match specified executable file.
[New LWP 25775]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./gesture_recognition_test_binary'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62
62 ../sysdeps/x86_64/multiarch/strlen-avx2.S: No such file or directory
进入gdb后
(gdb) where/ bt (where/bt两者效果一致)
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62
#1 0x00007fe7d36564d3 in _IO_vfprintf_internal (s=0x7fe7d39e5760 <_IO_2_1_stdout_>,
format=0x558fb3125350 "Tensor %3zu %-20s %10s %15s %10zu bytes (%4.1f MB) ", ap=ap@entry=0x7ffd8e703380) at vfprintf.c:1643
#2 0x00007fe7d365df26 in __printf (format=<optimized out>) at printf.c:33
#3 0x0000558fb3122263 in tflite::PrintInterpreterState(tflite::MicroInterpreter*) ()
#4 0x0000558fb3119147 in main ()
还有其他的命令...
来源:CSDN
作者:shuai_wen
链接:https://blog.csdn.net/u011279649/article/details/103669609