问题来源:
当我将要检查对比的两个tflite拷贝到和visualize.py同一个文件夹下面,并执行python visualize.py tflite.tflite tflite.html后遇到下图的报错:
回到源代码49行发现,原来C:\Users\iwtba\Downloads\tensorflow-master\third_party\flatbuffers下面确实没有flatc文件。
相同的问题也在github上被提到,那里也给出了大概的解决思路。解答者andrewginns 的电脑环境是ubuntu,但我是windows,所以下面我按自己的情况试着解决这个问题。
https://github.com/tensorflow/tensorflow/issues/18857
解决方法:
1.下载FlatBuffer :https://github.com/google/flatbuffers
2.安装CMake :https://cmake.org/
2.1 配置Cmake:https://jingyan.baidu.com/article/19192ad8dfa3d8e53e5707c8.html
3.解压第一步下载的zip文件,在第一级目录里打开命令行输入,
cmake -G "Visual Studio 16"
这里的16对应的是Visual Studio的版本号,根据下表对应的数字来,我的是VS2019,所以使用16
但是,紧接着我又遇到了报错
大概意思就是cmake没“看到”我的电脑装了VS2019,按照stackoverflow上的方法:
- Open Visual Studio
- Go to Tools -> Get Tools and Features
- In the "Workloads" tab enable "Desktop development with C++"
- Click Modify at the bottom right
不过,到这个时候我突然发现github上已经有人把预编译好的flatc上传上去了,我们可以直接去下载,不需要上面那些繁琐的步骤!链接:https://github.com/google/flatbuffers/releases
下载并解压好flatc.exe,把它复制到 tensorflow-master/third_party/flatbuffers 下面去,并在visualize.py里把相关代码改成:
if not os.path.exists(_BINARY):
_BINARY = resource_loader.get_path_to_datafile(
"C:/Users/iwtba/Downloads/tensorflow-master/third_party/flatbuffers")
注意上面路径里的斜杠是/,不是你粘贴过来的\ 。
结果搞了半天在国外一篇博文上发现,有大神做了一款模型可视化工具!链接:https://lutzroeder.github.io/netron/。
真香!有了它我就可以对比我导出的tflite跟官方的tflite有哪些不一样的地方了。