Skip to content

Instantly share code, notes, and snippets.

View szagoruyko's full-sized avatar

Sergey Zagoruyko szagoruyko

View GitHub Profile
@szagoruyko
szagoruyko / torch-opencv-blogpost.md
Created June 1, 2016 08:53 — forked from shrubb/torch-opencv-blogpost.md
"OpenCV bindings" post for Torch blog

OpenCV Bindings for Torch

The OpenCV library implements tons of useful image processing and computer vision algorithms, as well as the high-level GUI API. Written in C++, it has bindings in Python, Java, MATLAB/Octave, C#, Perl and Ruby. We present the Lua bindings that are based on Torch, made by VisionLabs with support from Facebook and Google Deepmind.

By combining OpenCV with scientific computation abilities of Torch, one gets an even more powerful framework capable of handling computer vision routines (e.g. face detection), interfacing video streams (including cameras), easier data visualization, GUI interaction and many more. In addition, most of the computationally intensive algorithms are available on GPU via Cutorch. All these features may be essentially useful for those dealing with deep learning applied to images.

Usage Examples

@szagoruyko
szagoruyko / torch-opencv-blogpost.md
Last active May 30, 2017 16:52 — forked from shrubb/torch-opencv-blogpost.md
"OpenCV bindings" post for Torch blog

OpenCV Bindings for Torch

The OpenCV library implements tons of useful image processing and computer vision algorithms, as well as the high-level GUI API. Written in C++, it has bindings in Python, Java, MATLAB/Octave, C#, Perl and Ruby. We present the Lua bindings that are based on Torch, made by VisionLabs with support from Facebook and Google Deepmind.

By combining OpenCV with scientific computation abilities of Torch, one gets an even more powerful framework capable of handling computer vision routines (e.g. face detection), interfacing video streams (including cameras), easier data visualization, GUI interaction and many more. In addition, most of the computationally intensive algorithms are available on GPU via Cutorch. All these features may be essentially useful for those dealing with deep learning applied to images.

Usage Examples

require 'xlua'
local grad = require 'autograd'
local tablex = require 'pl.tablex'
grad.optimize(true)
local function cast(x)
if type(x) == 'table' then
for k,v in pairs(x) do x[k] = cast(v) end
return x
else
@szagoruyko
szagoruyko / convertLinear2Conv1x1.lua
Created September 28, 2015 18:16 — forked from fmassa/convertLinear2Conv1x1.lua
Simple example on how to convert a Linear model to a 1x1 convolution
require 'nn'
-- you just need to provide the linear module you want to convert,
-- and the dimensions of the field of view of the linear layer
function convertLinear2Conv1x1(linmodule,in_size)
local s_in = linmodule.weight:size(2)/(in_size[1]*in_size[2])
local s_out = linmodule.weight:size(1)
local convmodule = nn.SpatialConvolutionMM(s_in,s_out,in_size[1],in_size[2],1,1)
convmodule.weight:copy(linmodule.weight)
convmodule.bias:copy(linmodule.bias)
@szagoruyko
szagoruyko / gist:5a85d194c0ed61e1a729
Last active August 29, 2015 14:27 — forked from soumith/gist:0f95facad88cbea68c6d
linear with no bias
local Linear, parent = torch.class('nn.NoBiasLinear', 'nn.Linear')
function Linear:__init(inputSize, outputSize)
parent.__init(self, inputSize, outputSize)
self.bias:fill(0)
end
function Linear:accGradParameters(input, gradOutput, scale)
scale = scale or 1
if input:dim() == 1 then