亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TensorFlow:使用 Tensorflow 2.2.0 將 SavedModel.pb

TensorFlow:使用 Tensorflow 2.2.0 將 SavedModel.pb

POPMUISE 2022-12-20 12:14:20
我一直在無休止地尋找一個 python 腳本或命令行函數來將 .pb 文件轉換為 .tflite。我試過使用 tflite_convert,但它返回錯誤:OSError:SavedModel 文件不存在于:C:/tensorflowTraining/export_dir/saved_model.pb/{saved_model.pbtxt|saved_model.pb}我還嘗試了一些腳本,例如:import tensorflow as togf = tf.compat.v1.GraphDef()m_file = open('saved_model.pb', 'rb')gf.ParseFromString(m_file.read())with open('somefile.txt', 'a') as the_file:    for n in gf.node:        the_file.write(n.name+'\n')file = open('somefile.txt', 'r')data = file.readlines()print("output name = ")print(data[len(data)-1])print("Input name = ")file.seek(0)print(file.readline())這將返回:發生異常:DecodeError意外的結束組標記。這個錯誤發生在第 4 行: gf.ParseFromString(m_file.read())如果有人可以提供工作腳本或命令行功能,那將非常有幫助,正如我研究過的那樣返回錯誤或無法正常運行。謝謝!
查看完整描述

1 回答

?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

你可以嘗試像下面這樣的東西TF2.2。


import tensorflow as tf 

graph_def_file = "./saved_model.pb"

tflite_file = 'mytflite.tflite'


input_arrays = ["input"]. # you need to change it based on your model

output_arrays = ["output"] # you need to change it based on your model

print("{} -> {}".format(graph_def_file, tflite_file))

converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(

  graph_def_file=graph_def_file,

  input_arrays=input_arrays,

  output_arrays=output_arrays,input_shapes={'input_mel':[ 1, 50, 80]})

# If there are multiple inputs, then update the dictionary above

tflite_model = converter.convert()

open(tflite_file,'wb').write(tflite_model)

在上面的代碼中,您需要使用與您的模型相對應的input_arrays, output_arrays, 和。input_shapes


查看完整回答
反對 回復 2022-12-20
  • 1 回答
  • 0 關注
  • 240 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號