5

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?

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

1 Comment

pytorch author here. pytorch contains a full lua engine. It will run either luajit (linux) or lua (mac). You can import your own lua classes now. See for example github.com/hughperkins/pytorch-residual-networks or github.com/hughperkins/cifar.pytorch
1

As was suggested by one of the Torch authors on torch7 maillist, you can try pytorch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.