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)
正如Torch作者之一在torch7 maillist上建议的那样,您可以尝试pytorch。在
我想你现在有了一个更好的解决方案,那就是lutorpy。 与pytorch不同的是,pythorch中有一个lua引擎,因此可以更灵活地导入任何lua模块并用python编写代码,而且易于使用和灵活。对于pytorch,只有很少的移植模块可以直接在python中使用。在
有了lutorpy,你可以在numpy和torch张量之间轻松快速地转换。在
对于您的情况,您可以这样用python编写代码:
不同图书馆的简要比较: How can I load and use torch deep learning models from python?
相关问题 更多 >
编程相关推荐