hughperkins / pytorch

Python wrappers for torch and lua
BSD 2-Clause "Simplified" License
431 stars 70 forks source link

Load trained model #15

Closed edgarriba closed 8 years ago

edgarriba commented 8 years ago

@hughperkins Do you support load an existing trained model?

hughperkins commented 8 years ago

Yes! I mean, on the lua side anyway. For example, you can have a look at https://github.com/hughperkins/pytorch-residual-networks/blob/pytorch/residual_trainer.lua#L58

But I guess you mean, can I load a .t7 directly into a Pytorch tensor, from the Python side? In which case... I need to think about that :-P

edgarriba commented 8 years ago

Yes, second use case. I want to interact with opencv python and a t7 file

hughperkins commented 8 years ago

Ok. Started looking at this in 6aa2f19f4 Seems like save maybe works. You might be able to add in load, using same approach? Otherwise I will look at this tomorrow-ish

edgarriba commented 8 years ago

thx!

hughperkins commented 8 years ago

Implemented in 0f129c0 You should be able to do:

import PyTorchAug

PyTorchAug.save('/tmp/foo.t7', sometensor)
result = PyTorchAug.load('/tmp/foo.t7')

You can look at test/test_save_load.py for an example

hughperkins commented 8 years ago

Can you confirm this does/doesnt work?

sunshineatnoon commented 8 years ago

@hughperkins This works fine, thanks for this great work!

hughperkins commented 8 years ago

Cool. Thank you @sunshineatnoon :-)

dyzhou2015 commented 7 years ago

Can I load a Gpu-trained model ? I mean the parameter of the model is CudaTensor. Thanks

wangdelp commented 7 years ago

Still not clear how to use trained model. I can use torch.load(file_path) to get the weights, but how do I use these weights to initialize the network? Thank you.