I have a program is written in python and I have model ConvNet trained using Toch7. I would like to call forward and backpro to the model from python program as I find difficult and hard to write it again in lua.
Any idea please?
I think you now have a much better solution, which is lutorpy. Different from pytorch, you have a lua engine in python, so it's more flexible to import any lua module and code in python, and it's easy to use and flexible. For pytorch you only have very few ported module which you can directly use in python.
With lutorpy, you can convert between numpy and torch tensor easily and very fast.
For you case, you can write your code in python like this:
import numpy as np
import lutorpy as lua
model = torch.load('PATH TO YOUR MODEL FILE')
# generate your input data with numpy
arr = np.random.randn(100)
# convert your numpy array into torch tensor
x = torch.fromNumpyArray(arr)
# apply model forward method with "._" syntax(which is equivalent to ":" in lua)
y = model._forward(x)
A brief comparison between different library: How can I load and use torch deep learning models from python?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With