简体   繁体   中英

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'.

to use it in android I want to convert it to tflite file so I used this code

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')
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.

You need to fix the TFLite Converter code as given here

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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