pythonlessons / mltu

Machine Learning Training Utilities (for TensorFlow and PyTorch)
MIT License
160 stars 100 forks source link

no module named tf2onnx #33

Closed pigking0126 closed 9 months ago

pigking0126 commented 9 months ago

it seems that using 'pip install mltu' doesn't install tf2onnx

from mltu.tensorflow.callbacks import Model2onnx
#callbacks
model2onnx = Model2onnx(f"{configs.model_path}/model.h5")

cause after the train process has been done, it will return error: No module named tf2onnx

so now i only have model.h5, but since I use CTCloss and CWERMetric and stuff like this, I have a hard time trying to export it to onnx file is there any function in this module that can do this for me? I can only find callback function not direct tf to onnx.

DucBac99 commented 9 months ago

I am also having the same problem please help me

pythonlessons commented 9 months ago

Hey, thanks.

Usually, you can do the conversion in the following way: tf2onnx.convert.from_keras(model, output_path=onnx_model_path)

But, I'll create a change, so if you don't have installed tf2onnx and onnx packages, it will raise an error when you import Model2onnx callback

I don't want to add these packages into mltu, because if we use PyTroch for training, they are not necessary. PyTorch have their own conversion integrated into torch

DucBac99 commented 9 months ago

What should I do to fix that error?

DucBac99 commented 9 months ago

I tried installing tf2onnx and onnx by pip install but when train reached epoch 317 the process stopped, here are the error details please help me check Epoch 317: early stopping 2023-09-13 13:24:46.914593: I tensorflow/core/grappler/devices.cc:75] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA or ROCm support) 2023-09-13 13:24:46.931476: I tensorflow/core/grappler/clusters/single_machine.cc:357] Starting new session 2023-09-13 13:24:49.225700: I tensorflow/core/grappler/devices.cc:75] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA or ROCm support) 2023-09-13 13:24:49.242155: I tensorflow/core/grappler/clusters/single_machine.cc:357] Starting new session 2023-09-13 13:24:50.268365: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:375] MLIR V1 optimization pass is not enabled @pythonlessons

pythonlessons commented 9 months ago

What gpu you have? this error is not related with code, the issue might be with drivers or tensorflow, not sure...

DucBac99 commented 9 months ago

image This is my gpu, can I run it on cpu?

pythonlessons commented 9 months ago

Yes, you gpu is too old, I think it doesn't support onnx, you can try convert it using cpu

pythonlessons commented 9 months ago

In new version 1.1.1 the Import error will be raised then you try to: from mltu.tensorflow.callbacks import Model2onnx if you don't have tf2onnx and onnx installed