Skip to content

Operation Feedback and Utilities

Brian Broll edited this page Oct 6, 2016 · 2 revisions

Operations can provide real-time notebook-esque feedback mechanisms using deepforge in the operation implementation.

Graphing

Graphs can be created with deepforge.Graph. A graph w/ the title 'My Example Graph' can be created as follows:

local graph = deepforge.Graph('My Example Graph')

Next, lines can be added to the graph using the line method:

local firstLine = graph:line('My First Line')
local secondLine = graph:line('My Second Line')

Finally, points can be added to a line using the add method:

local x = 1
local x2 = 2
local y = 3
local y2 = 4

firstLine:add(x, y)
secondLine:add(x2, y2)

Images

Images can be displayed in two different ways:

-- inspired by image.save from the torch package
deepforge.image('Red Car', tensor)

or using the deepforge.Image constructor

local img = deepforge.Image('Red Car', tensor)
img:title('Blue Car')  -- changing the title from 'Red Car' to 'Blue Car'
img:update(blue_car_tensor)  -- changing the image to the image in blue_car_tensor

Multithreading (using the threads package)

This is not a feedback mechanism but is included as it is another function included in the deepforge object and is useful when creating custom operations.

When using the threads library, the environment sometimes needs to be set up so that it contains various layer definitions, classes, etc, before it can create a thread which uses the given classes, definitions, etc. An example from the threads github readme is below:

require 'nn'
local threads = require 'threads'
local model = nn.Linear(5, 10)
threads.Threads(
    2,
    function(idx)                      -- This code is OK.
        require 'nn'
    end,                               -- child threads know nn.Linear when deserializing f2
    function(idx)
        local myModel = model:clone()  -- because f1 has already been executed
    end
)

In order to support multithreading in deepforge, deepforge.initialize can be used to load all custom layer definitions and classes so that models containing these types can be used in the spawned threads. An example is shown below.

-- model is input to the given operation which may have a custom layer
local threads = require 'threads'
threads.Threads(
    2,
    deepforge.initialize,
    function(idx)
        local myModel = model:clone()  -- because all custom layer definitions are now loaded in the thread
    end
)
Clone this wiki locally