windows Docker tengine模型转换工具的安装与使用
最近在开发板上用Tengine做模型推理,遇到了模型不能使用的问题,对模型转换工具安装与使用做一个记录
模型转换工具安装
官网
找一个目录把官网代码clone下来
然后再这个目录
mkdir build && cd build
cmake ..
make -j`nproc` && make install
cmake阶段遇到了如下问题,反正也不用oneflow,就直接加参数了cmake -DBUILD_ONEFLOW_SERIALIZER=OFF ..
root@531776024d67:/home/tengine/build# cmake ..
-- CMAKE_INSTALL_PREFIX = /home/tengine/build/install
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:59 (message):
Please upgrade your cmake (maybe by "pip3 install -U cmake") or disable
OneFlow serializer by "cmake -DBUILD_ONEFLOW_SERIALIZER=OFF .."
-- Configuring incomplete, errors occurred!
See also "/home/tengine/build/CMakeFiles/CMakeOutput.log".
See also "/home/tengine/build/CMakeFiles/CMakeError.log".
模型转换工具使用
我的需求是pd转tmfile,直接用模型转换工具未能成功,之后采用pd转tflite,tflite转tmfile
pd转tflite
import tensorflow as tf
# Convert the model
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir) # path to the SavedModel directory
tflite_model = converter.convert()
# Save the model.
with open('model.tflite', 'wb') as f:
f.write(tflite_model)
tflite转tmfile
./install/bin/convert_tool -f tflite -m ../model.tflite -o model.tmfile