python - 如何将 pb 文件转换为 tf lite?
问题描述
我正在使用 Inception v3 进行图像分类,我重新训练了生成 2 个文件“retrained_graph.pb”和“retrained_lables”的模型。
在android中使用它我想将它转换为tflite文件所以我使用了这段代码
import tensorflow as tf
from tensorflow import lite
converter = lite.TFLiteConverter.from_frozen_graph(
'retrained_graph.pb' ,'DecodeJpeg/contents', 'final_result')
tflite_model = converter.convert()
open("test.tflite", "wb").write(tflite_model)
我收到此错误
回溯(最后一次调用):
文件“tfconvert.py”,第 4 行,在“retrained_graph.pb”、“DecodeJpeg/contents”、“final_result”)
文件“C:\Users\Thakkar\AppData\Local\Programs\ Python\Python36\lib\site-packages\tensorflow_core\lite\python\lite.py”,第 705 行,在 from_frozen_graph sess.graph,input_arrays)文件“C:\Users\Thakkar\AppData\Local\Programs\Python\Python36 \lib\site-packages\tensorflow_core\lite\python\util.py",第 122 行,在 get_tensors_from_tensor_names",".join(invalid_tensors))) ValueError: Invalid tensors 'D,e,c,o,d,e, J,p,e,g,/,c,o,n,t,e,n,t,s' 被发现。
解决方案
您需要修复此处给出的 TFLite 转换器代码
converter = lite.TFLiteConverter.from_frozen_graph(
graph_def_file='retrained_graph.pb' ,
input_arrays=['DecodeJpeg/contents'],
output_arrays=['final_result']
)
推荐阅读
- build - 使用 Azure Devops 构建类库项目
- python - Heroku dyno 不写入文件
- scala - Scala Spark 反向分组 groupBy
- php - 处理 JSON 文件中的非 UTF-8 数据
- spring - 如何将 dockerized spring boot 应用程序连接到 dockerized postgres
- python - 如何使用 sklearn 管道跟踪 catboost 的分类索引
- c - memcpy regex_t 安全吗?
- sql - Visual Studio 诊断工具将查询变量显示为 SQL_VARIANT。这是个问题吗?
- css - 有没有办法为 IE 动态创建 CSS 网格?
- symfony - 我想排除某些路由需要 JWT 令牌