Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Server Using Lua/ Torch7

Tags:

http

api

torch

lua

I'm starting to learn Torch7 to get into the machine learning/ deep learning field and I'm finding it fascinating (and very complicated haha). My main concern, however, is if I can turn this learning into an application - mainly can I turn my Torch7 Lua scripts into a server that an app can use to perform machine learning calculations? And if it's possible, how?

Thank you

like image 459
Rob Avatar asked Mar 30 '15 19:03

Rob


1 Answers

You can use waffle. Here's the hello world example on it's page:

local app = require('waffle')

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

app.listen()

lets say your algorithm is a simple face detector. The input is an image and the output is the face detections in some json format. You can do the following:

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()

That way your algorithm can be used as an independent service.

like image 66
amirbar Avatar answered Nov 03 '22 11:11

amirbar