Call torch7 (Lua) function from python?

I have a program written in python, and I have a ConvNet model trained using Toch7. I would like to call forward and backpro for the model from the python program, since it is hard and hard for me to write it again in lua.

Any idea please?

+5
source share
2 answers

I think you now have a much better solution that is lutorpy . Unlike pytorch, you have a lua engine in python, so it’s more flexible to import any lua module and code into python, and it is easy to use and flexible. For pytorch, you only have very few ported modules that you can directly use in python.

With lutorpy you can easily and quickly convert between tensor and torch tensor.

In this case, you can write your code in python as follows:

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 libraries: How to download and use deep torch training models from python?

+2
source

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

+1
source

Source: https://habr.com/ru/post/1236005/


All Articles