hughperkins / pytorch

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

Can I load Torch trained model file by Pytorch #5

Closed erogol closed 8 years ago

erogol commented 8 years ago

I want to use torch trained deep learning model from python. Is it able to do that?

hughperkins commented 8 years ago

Yes ... you can create a lua class, that trains your model, or loads an existing model, and call this from Python. You can pass in new examples from python to the model, to predict on. I would first have a look at simpleexample/pybit.py and simpleexample/luabit.lua for an example of python code that loads a lua class, creates an object from it, and calls methods on it. That lua class could load your model, and pass new examples to your model for prediction.

hughperkins commented 8 years ago

Actually, I will write an example for this :-)

erogol commented 8 years ago

Thanks :)

hughperkins commented 8 years ago

Ok, I didnt add prediction, but covers:

51cbc09

https://github.com/hughperkins/pytorch/tree/master/examples/luamodel

hughperkins commented 8 years ago

Updated so you can pass numpy tensors in directly now 66bb797

hughperkins commented 8 years ago

added prediction in 9c05864

Also added methods tensorOne.eq(tensorTwo), and tensor.sum() to PyTorch.xxxTensor objects

You'll need to pip install docopt to use runner.py now

hughperkins commented 8 years ago

Updated in 0a9e04a to convert the output predictions tensor to numpy array, before calculating number correct

hughperkins commented 8 years ago

To what extent does this do approximately what you want? (The other approach is to instantiate nn modules directly from the python; depends what you want really)

hughperkins commented 8 years ago

You can load directly now, without needing to create a lua class, see https://github.com/hughperkins/pytorch/issues/15