Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

ERROR:root:Can not load PyTorch model. Please make surethat model saved like torch.save(model, PATH) #8

Open
IvanStoykov opened this issue Oct 25, 2021 · 7 comments

Comments

@IvanStoykov
Copy link

I'm trying to convert a YOLOv5 best.pt weights file to a .tflite file so we can deploy the model on a flutter app.

This is the code:

`import torch
weights_path = '/content/drive/MyDrive/Weights/best.pt'
yolo_path = '/content/yolov5'

model = torch.hub.load(yolo_path, 'custom', weights_path, source='local') # local repo
torch.save(model, '/content/pipeline.pt' )`

You can also go straight to the colab for all the colde.
https://colab.research.google.com/drive/19JeOkrxlGP6KtkfGbrkO87COc4pvSZSE?usp=sharing

I assume I'm not saving the model how the converter wants it, but I can't figure it out.
Can you please explain exactly how the file needs to be saved so the code will work ?

Thanks a lot in advance!

@lawsonX
Copy link

lawsonX commented Nov 3, 2021

I got exactly the same problem! Can't load pytorch model

@trueangle
Copy link

trueangle commented Nov 15, 2021

@IvanStoykov To understand what causes the problem you can log the exception on 72 line in convertert.py, simply write logging.error(str(e)) and run the script again. The problem may be in the wrong path to your model and not in pytorch itself.

Anyway check your saving script, be sure that you save the entire model, not only the model parameters.

@larrywal-express
Copy link

I also faced the same problem

@celikmustafa89
Copy link

while I am running this command:
python3.8 -m torch2tflite.converter --torch-path model/model.pth --tflite-path model.tflite --target-shape 225 225 3 --seed 1
the error:
ERROR:root:Can not load PyTorch model. Please make sure that model saved like 'torch.save(model, PATH)'

@ralienpp
Copy link

I have the same error, the problem occurs here model = model.eval() https://github.com/omerferhatt/torch2tflite/blob/master/torch2tflite/converter.py#L65

For me, torch.load returns an OrderedDict, which doesn't have an eval method, hence the error: 'collections.OrderedDict' object has no attribute 'eval'. Clearly, this is not happening because the path to the PyTorch model is incorrect.

@jeungmin717
Copy link

@ralienpp did you solve it ? I have the same issue

@ralienpp
Copy link

I don't remember, unfortunately. Most likely it is because I abandoned the prototype I was working on at that time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants