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

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

將 save_model.pb 轉換為 model.tflite

將 save_model.pb 轉換為 model.tflite

海綿寶寶撒 2023-07-05 10:08:10
張量流版本:2.2.0操作系統:Windows 10我正在嘗試將 saving_model.pb 轉換為 tflite 文件。這是我正在運行的代碼:import tensorflow as tf# Convertconverter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir='C:\Data\TFOD\models\ssd_mobilenet_v2_quantized')tflite_model = converter.convert()fo = open("model.tflite", "wb")fo.write(tflite_model)fo.close此代碼在轉換時出錯:  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\convert.py", line 196, in toco_convert_protos    model_str = wrap_toco.wrapped_toco_convert(model_flags_str,  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\wrap_toco.py", line 32, in wrapped_toco_convert    return _pywrap_toco_api.TocoConvert(Exception: <unknown>:0: error: loc("Func/StatefulPartitionedCall/input/_0"): requires all operands and results to have compatible element types<unknown>:0: note: loc("Func/StatefulPartitionedCall/input/_0"): see current operation: %1 = "tf.Identity"(%arg0) {device = ""} : (tensor<1x?x?x3x!tf.quint8>) -> tensor<1x?x?x3xui8>During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "c:/Data/TFOD/convert.py", line 13, in <module>    tflite_model = converter.convert()  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\lite.py", line 1076, in convert    return super(TFLiteConverterV2, self).convert()  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\lite.py", line 899, in convert    return super(TFLiteFrozenGraphConverterV2,  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\lite.py", line 629, in convert    result = _toco_convert_impl(
查看完整描述

2 回答

?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

好吧,我終于解決了!


我所做的是使用 tf-nightly 并使用以下 Python 腳本:


import tensorflow as tf


saved_model_dir = "C:/Data/TFOD/models/ssd_mobilenet_v2_quantized/tflite"

converter = tf.lite.TFLiteConverter.from_saved_model(

    saved_model_dir, signature_keys=['serving_default'])

converter.optimizations = [tf.lite.Optimize.DEFAULT]

converter.experimental_new_converter = True

converter.target_spec.supported_ops = [

    tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]

tflite_model = converter.convert()


fo = open(

    "C:/Data/TFOD/models/ssd_mobilenet_v2_quantized/tflite/model.tflite", "wb")

fo.write(tflite_model)

fo.close

這解決了問題,您可以轉換為 .tflite


查看完整回答
反對 回復 2023-07-05
?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

export_tflite_ssd_graph.pyTensorflow在該文件夾中提供了一個名為 python 文件model/object_detection,可用于將保存的模型轉換為 tflite 格式。


python?object_detection/export_tflite_ssd_graph.py?\
????--pipeline_config_path?path/to/ssd_mobilenet.config?\
????--trained_checkpoint_prefix?path/to/model.ckpt?\
????--output_directory?path/to/exported_model_directory

預期的輸出將位于目錄
path/to/exported_model_directory (如果不存在則創建),其
內容為:

  • tflite_graph.pbtxt

  • tflite_graph.pb

如需完整使用,您可以閱讀文件內的注釋。


查看完整回答
反對 回復 2023-07-05
  • 2 回答
  • 0 關注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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