HTTP服务器使用Lua/Torch7

Rob*_*Rob 5 api lua http torch

我开始学习Torch7进入机器学习/深度学习领域,我发现它很迷人(而且非常复杂哈哈).然而,我主要担心的是,如果我可以将这种学习转化为一个应用程序 - 主要是我可以将我的Torch7 Lua脚本变成一个应用程序可以用来执行机器学习计算的服务器吗?如果有可能,怎么样?

谢谢

小智 5

你可以用华夫饼干.这是它页面上的hello world示例:

local app = require('waffle')

app.get('/', function(req, res)
   res.send('Hello World!')
end)

app.listen()
Run Code Online (Sandbox Code Playgroud)

假设您的算法是一个简单的人脸检测器.输入是图像,输出是某种json格式的面部检测.您可以执行以下操作:

local app = require('waffle')
require 'graphicsmagick'
require 'MyAlgorithm'

app.post('/', function(req, res)
  local img, detections, outputJson
  img = req.form.image_file:toImage()
  detections = MyAlgorithm.detect(img:double())
  outputJson = {}
  if (detections ~= nil) then
    outputJson.faceInPicture = true
    outputJson.faceDetections = detections
  else
    outputJson.faceInPicture = false
    outputJson.faceDetections = nil
  end
  res.json(outputJson)
end)

app.listen()
Run Code Online (Sandbox Code Playgroud)

这样,您的算法可以用作独立服务.


Pau*_*nko 2

您应该将 Torch 视为一个库(即使您可能将其作为独立的可执行文件访问)。可以从一些可通过 HTTP 访问的 Lua 代码中使用该库。Lua 代码可能在OpenResty内部运行,它将处理所有 HTTP 交互,并且您可以获得与 OpenResty 可以配置为使用 LuaJIT 相同的性能。

另一种选择是使用基于 luasocket 和 copas 库(例如Xavante )的 HTTP 处理或使用LuaWebserver页面上列出的选项之一。