我正在尝试将模型从冻结图.pb
保存到tensorflowlite。我正在使用Google colab。我尝试使用Pydrive将文件上传为saved_model2.pb
,但尝试使用.from_frozen_graph
时却出错了
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
file_obj = drive.CreateFile({'id': '15vnDl_fBztBT4nzVYQgzJFbPBMofQ2KJ'})
file_obj.GetContentFile('saved_model2.pb')
import tensorflow as tf
graph_def_file = "saved_model2.pb"
tflite_file = "retrained_graph_eyes1z.lite"
input_arrays = ["input"]
output_arrays = ["kinetics-i3d/Predictions/Softmax"]
converter = tf.lite.TFLiteConverter.from_frozen_graph(
graph_def_file,
input_arrays,
output_arrays)
tflite_model = converter.convert()
open(tflite_file, "wb").write(tflite_model)
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()
files.download(tflite_file)
这是我收到的错误消息
DecodeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in from_frozen_graph(cls, graph_def_file, input_arrays, output_arrays, input_shapes)
607 graph_def = _graph_pb2.GraphDef()
--> 608 graph_def.ParseFromString(file_content)
609 except (_text_format.ParseError, DecodeError):
DecodeError: Error parsing message
During handling of the above exception, another exception occurred:
UnicodeDecodeError Traceback (most recent call last)
1 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in from_frozen_graph(cls, graph_def_file, input_arrays, output_arrays, input_shapes)
613 if not isinstance(file_content, str):
614 if PY3:
--> 615 file_content = file_content.decode("utf-8")
616 else:
617 file_content = file_content.encode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdb in position 1: invalid continuation byte