简体   繁体   English

如何将 pb 文件转换为 tf lite?

[英]how do i convert pb file to tf lite?

I'm using Inception v3 for image classification, I retrained the model which generated 2 files 'retrained_graph.pb' and 'retrained_lables'.我正在使用 Inception v3 进行图像分类,我重新训练了 model,它生成了 2 个文件“retrained_graph.pb”和“retrained_lables”。

to use it in android I want to convert it to tflite file so I used this code在 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)

I'm getting this error我收到此错误

Traceback (most recent call last):回溯(最近一次通话最后):
File "tfconvert.py", line 4, in 'retrained_graph.pb','DecodeJpeg/contents', 'final_result')文件“tfconvert.py”,第 4 行,在 'retrained_graph.pb'、'DecodeJpeg/contents'、'final_result')
File "C:\Users\Thakkar\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\lite\python\lite.py", line 705, in from_frozen_graph sess.graph, input_arrays) File "C:\Users\Thakkar\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\lite\python\util.py", line 122, in 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' were found.文件“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:找到了无效的张量 'D,e,c,o,d,e,J,p,e,g,/,c,o,n,t,e,n,t,s'。

You need to fix the TFLite Converter code as given here您需要修复此处给出的 TFLite 转换器代码

converter = lite.TFLiteConverter.from_frozen_graph(
   graph_def_file='retrained_graph.pb' ,
   input_arrays=['DecodeJpeg/contents'],
   output_arrays=['final_result']
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM