Torch Demo

Torch7 is a versatile numeric computing framework and machine learning librar that extends Lua. Its goal is to provide a flexible environment to design and train learning machines. Flexibility is obtained via Lua, an extremely lightweight scripting language. High performance is obtained via efficient OpenMP/SSE an CUDA implementations of low-level numeric routines. Torch7 can easily be interfaced to third-party software thanks to Lua’s light interface.
Ronan Collobert et al.

require 'image';


itorch.image({image.lena(), image.lena(), image.lena()})

_config.yml

require 'nn'
m=nn.SpatialConvolution(3,32,25,25)
itorch.image(m.weight)

_config.yml

n = nn.SpatialConvolution(1,16,12,12)
res = n:forward(image.rgb2y(image.lena()))
itorch.image(res:view(16,1,501,501))

_config.yml

require 'image'
img = image.load('/home/cobalt/Pictures/dovahkin.png', 3, 'double')
itorch.image(img)

_config.yml

require 'nn'
n = nn.SpatialConvolution(1,64,16,16)
itorch.image(n.weight)

_config.yml

n = nn.SpatialConvolution(1,16,12,12)
res = n:forward(image.rgb2y(img))
itorch.image(res:view(16,1,501,501))


itorch.audio('volkswagen.mp3')
itorch.video('small.mp4')
itorch.html('<p><b>Hi there!</b> this is arbitrary HTML</p>');
x1 = torch.randn(40):mul(100)
y1 = torch.randn(40):mul(100)
x2 = torch.randn(40):mul(100)
y2 = torch.randn(40):mul(100)
x3 = torch.randn(40):mul(200)
y3 = torch.randn(40):mul(200)


Plot = require 'itorch.Plot'


?torch.cmul




+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
[res] torch.cmul([res,] tensor1, tensor2)


Element-wise multiplication of tensor1 by tensor2 . The number
of elements must match, but sizes do not matter.
 > x = torch.Tensor(2,2):fill(2)
> y = torch.Tensor(4):fill(3)
> x:cmul(y)
> = x
 6  6
 6  6
[torch.Tensor of dimension 2x2] 

 z=torch.cmul(x,y) returns a new tensor.

 torch.cmul(z,x,y) puts the result in z .

 y:cmul(x) multiplies all elements of y with corresponding elements 
of x .

 z:cmul(x,y) puts the result in z .	
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	






plot = Plot():circle(x1, y1, 'red', 'hi'):circle(x2, y2, 'blue', 'bye'):draw()
plot:circle(x3,y3,'green', 'yolo'):redraw()
plot:title('Scatter Plot Demo'):redraw()
plot:xaxis('length'):yaxis('width'):redraw()
plot:legend(true)
plot:redraw()
-- line plots
plot = Plot():line(x1, y1,'red','example'):legend(true):title('Line Plot Demo'):draw()
-- segment plots
plot = Plot():segment(x1, y1, x1+10,y1+10, 'red','demo'):title('Segment Plot Demo'):draw()
-- quiver plots
xx = torch.linspace(-3,3,10)
yy = torch.linspace(-3,3,10)
local function meshgrid(x,y)
   local xx = torch.repeatTensor(x, y:size(1),1)
   local yy = torch.repeatTensor(y:view(-1,1), 1, x:size(1))
    return xx, yy
end
Y, X = meshgrid(xx, yy)
U = -torch.pow(X,2) + Y -1
V =  X - torch.pow(Y,2) +1
plot = Plot():quiver(U,V,'red','',10):title('Quiver Plot Demo'):draw()
-- quads/rectangles
x1=torch.randn(10)
y1=torch.randn(10)
plot = Plot():quad(x1,y1,x1+1,y1+1,'red',''):draw()
-- histogram
x=torch.randn(10000)
lx = torch.log(x):add(1)
plot = Plot():histogram(x):histogram(lx):title('Histogram of a gaussian draw'):draw() 

-mkc practice

Written on April 11, 2015