![](/img/trans.png)
[英]How to convert Tensorflow 2.* trained with Keras model to .onnx format?
[英]I trained a model in torch and then convert it to caffe and after that to tf. How to convert it now to onnx?
我在 Torch 中訓練了一個 Resnet 模型。 然后,我將其轉換為 caffe 和 tflite。 現在我想將其轉換為 onnx。 我該怎么做? 我嘗試該命令:
python3 -m tf2onnx.convert --tflite resnet.lite --output resnet.lite.onnx --opset 13 --verbose
因為模型的當前格式是tflite,
並得到了那個錯誤:
return packer_type.unpack_from(memoryview_type(buf), head)[0]
struct.error: unpack_from requires a buffer of at least 11202612 bytes for unpacking 4 bytes at offset 11202608 (actual buffer size is 2408448)
謝謝。
您可以嘗試類似此結帳鏈接的操作,您可能需要在開始轉換之前凍結模型層。
pip install onnxruntime
pip install git+https://github.com/onnx/tensorflow-onnx
python -m tf2onnx.convert --saved-model ./checkpoints/yolov4.tf --output model.onnx --opset 11 --verbose
你可以試試這個也鏈接
pip install tf2onnx
import tensorflow as tf
import tf2onnx
import onnx
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(4, activation="relu"))
input_signature = [tf.TensorSpec([3, 3], tf.float32, name='x')]
# Use from_function for tf functions
onnx_model, _ = tf2onnx.convert.from_keras(model, input_signature, opset=13)
onnx.save(onnx_model, "dst/path/model.onnx")
你應該嘗試檢查你的模型文件,也許你有一個錯誤的文件,這個錯誤就是因為這個。 嘗試再次復制/下載文件,然后嘗試 tf 轉換:
python3 -m tf2onnx.convert --tflite resnet.lite --output resnet.lite.onnx --opset 13 --verbose
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.