omerferhatt / torch2tflite

PyTorch to TensorFlow Lite converter
MIT License
181 stars 43 forks source link

Issue in the model converting #4

Closed wenjingyang closed 3 years ago

wenjingyang commented 3 years ago

Hi, I had an error below when the code is in torch.onnx.export. I doubt the problem is the model isn't loaded completely but I'm not sure. Is it possible to provide any model sample to verify my code environment. Thanks! 'dict' object has no attribute 'training'

omerferhatt commented 3 years ago

If you can share error trace, I can check.

wenjingyang commented 3 years ago

Thanks for your help. The model is generated from https://github.com/Alexander-H-Liu/End-to-end-ASR-Pytorch

Traceback (most recent call last): File "/home/xx/3rdParty/torch2tflite/converter/torch_to_tflite.py", line 49, in torch_to_onnx torch.onnx.export( File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/init.py", line 271, in export return utils.export(model, args, f, export_params, verbose, training, File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/utils.py", line 88, in export _export(model, args, f, export_params, verbose, training, input_names, output_names, File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/utils.py", line 679, in _export with select_model_mode_for_export(model, training): File "/home/xx/anaconda3/envs/torch/lib/python3.8/contextlib.py", line 113, in enter return next(self.gen) File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/utils.py", line 38, in select_model_mode_for_export is_originally_training = model.training AttributeError: 'dict' object has no attribute 'training'

funmonty commented 3 years ago

+1. Getting the same issue.

molyswu commented 3 years ago

+1. Getting the same issue.

supriyaarun27 commented 3 years ago

+1. Getting the same issue.

nedicd commented 3 years ago

+1. Getting the same issue.

omerferhatt commented 3 years ago

Hello, sorry for late response. I am able to reproduce the error too. I'll update it when I fixed.

mozeqiu commented 3 years ago

Thanks for your help. The model is generated from https://github.com/Alexander-H-Liu/End-to-end-ASR-Pytorch

Traceback (most recent call last): File "/home/xx/3rdParty/torch2tflite/converter/torch_to_tflite.py", line 49, in torch_to_onnx torch.onnx.export( File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/init.py", line 271, in export return utils.export(model, args, f, export_params, verbose, training, File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/utils.py", line 88, in export _export(model, args, f, export_params, verbose, training, input_names, output_names, File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/utils.py", line 679, in _export with select_model_mode_for_export(model, training): File "/home/xx/anaconda3/envs/torch/lib/python3.8/contextlib.py", line 113, in enter return next(self.gen) File "/home/xx/anaconda3/envs/torch/lib/python3.8/site-packages/torch/onnx/utils.py", line 38, in select_model_mode_for_export is_originally_training = model.training AttributeError: 'dict' object has no attribute 'training'

I suggest to try the steps separately, and then take a closer look at the way of saving and loading the two models of pytorch and which way of saving your own

mozeqiu commented 3 years ago

Hi, I had an error below when the code is in torch.onnx.export. I doubt the problem is the model isn't loaded completely but I'm not sure. Is it possible to provide any model sample to verify my code environment. Thanks! 'dict' object has no attribute 'training'

I also have this problem, because when saving the model only the model parameters are saved, but the model structure is not saved, so you must first create your model structure when loading the model

omerferhatt commented 3 years ago

Please check last commit, and as @mozeqiu said don't forget to save whole model with torch.save(model, PATH)