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()})
require 'nn'
m=nn.SpatialConvolution(3,32,25,25)
itorch.image(m.weight)
n = nn.SpatialConvolution(1,16,12,12)
res = n:forward(image.rgb2y(image.lena()))
itorch.image(res:view(16,1,501,501))
require 'image'
img = image.load('/home/cobalt/Pictures/dovahkin.png', 3, 'double')
itorch.image(img)
require 'nn'
n = nn.SpatialConvolution(1,64,16,16)
itorch.image(n.weight)
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
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[1;35m[res] torch.cmul([res,] tensor1, tensor2)[0m
Element-wise multiplication of[0;32m tensor1 [0mby[0;32m tensor2 [0m. The number
of elements must match, but sizes do not matter.
[0;36m[0;36m > 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] [0m[0m
[0;32m z=torch.cmul(x,y) [0mreturns a new tensor.
[0;32m torch.cmul(z,x,y) [0mputs the result in[0;32m z [0m.
[0;32m y:cmul(x) [0mmultiplies all elements of[0;32m y [0mwith corresponding elements
of[0;32m x [0m.
[0;32m z:cmul(x,y) [0mputs the result in[0;32m z [0m.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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