optimum
optimum copied to clipboard
How to convert a model(tf_model.h5) with tokenizer folder to the onnx format
Feature request
I have trained the TensorFlow model using the Transformers library and saved the trained model and tokenizer in a folder named MODEL_WITH_TOKENIZER. The model is stored inside the folder in a .h5 format - tf_model.h5
Here is the folder structure.
I want to convert the model to .onnx format Should I convert the entire MODEL_WITH_TOKENIZER folder to .onnx or only the tf_model.h5 file to onnx? what are the steps
Motivation
Hi, I have trained the TensorFlow model using the Transformers library and saved the trained model and tokenizer in a folder named MODEL_WITH_TOKENIZER. The model is stored in the .h5 format - model.h5
Here is the folder structure.
I want to convert the model to .onnx format
Should I convert the entire MODEL_WITH_TOKENIZER folder to .onnx or only the tf_model.h5 file to onnx?
what are the steps
Your contribution
I have trained the TensorFlow model using the Transformers library and saved the trained model and tokenizer in a folder named MODEL_WITH_TOKENIZER. The model is stored in the .h5 format - tf_model.h5
Here is the folder structure.
I want to convert the model to .onnx format
Should I convert the entire MODEL_WITH_TOKENIZER folder to .onnx or only the tf_model.h5 file to onnx?
what are the steps
@fxmarty any info?
@pradeepdev-1995 Thank you for the request. You can give a try to pip install optimum[exporters-tf] and
optimum-cli export onnx --model /path/to/your/model --framework tf onnx_output/
should (hopefully) work. You may need to specify the --task argument as well.
@fxmarty I am using an Ubuntu machine and after installing with this pip install optimum[exporters-tf] found two issues
1 - Error optimum-cli: command not found
2 - The model object in
optimum-cli export onnx --model /path/to/your/model --framework tf onnx_output/
should be the tf_model.h5 file or the folder MODEL_WITH_TOKENIZER (which contains all the model and tokenizer files that I put in the screenshot)
About 1., can you try: pip uninstall optimum && pip install optimum[exporters-tf]. What are the install logs?
About 2., I'll try to reproduce, thank you.
@fxmarty
I am using ubuntu machine with Python 3.8.16 . The pip install optimum[exporters-tf] not installing it showcasing the given error
So installed via
pip install optimum[all] which didn't raise any error and was installed successfully.
So should i must use pip install optimum[exporters-tf] itself?