Skip to content

Instantly share code, notes, and snippets.

View andreaskoepf's full-sized avatar

Andreas Köpf andreaskoepf

View GitHub Profile
@andreaskoepf
andreaskoepf / conv_autoencoder.lua
Created September 16, 2015 00:57
mini single layer denoising auto-encoder experiment
require 'image'
require 'nngraph'
require 'optim'
-- mini single layer denoising auto-encoder experiment
-- (v1: no weight tying yet)
-- Andreas Köpf 2015-09-16
input = image.lena() -- 3x512x512
input_size = input:size()
@andreaskoepf
andreaskoepf / bottleneck_autoencoder.lua
Created September 16, 2015 01:03
mini bottleneck auto-encoder weight tying demo
require 'nn'
-- mini bottleneck auto-encoder weight tying demo
net = nn.Sequential()
net:add(nn.Linear(8, 8))
net:add(nn.PReLU())
net:add(nn.Linear(8, 3))
net:add(nn.PReLU())
net:add(nn.Linear(3, 8))
@andreaskoepf
andreaskoepf / rotationdistance.lua
Created October 19, 2015 22:26
experimental torch rotation distance criterion for quaternions
local RotationDistance, parent = torch.class('RotationDistance', 'nn.Criterion')
function RotationDistance:__init(weights)
parent.__init(self)
end
function RotationDistance:updateOutput(input, target)
-- acos(abs(<a,b> / norm(a) / norm(b))) + abs(1 - norm(a))
local one = torch.ones(input:size(1)):cuda()
local a = torch.cmul(input, target):sum(2):cdiv(torch.cmul(input:norm(2, 2), target:norm(2, 2))):abs():clamp(-1, 1):acos()
@andreaskoepf
andreaskoepf / JobQueue.cs
Last active October 22, 2015 21:24
Rx JobQueue
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
@andreaskoepf
andreaskoepf / torch_obj_versioning.lua
Last active November 27, 2015 23:03
Demo for custom 'read' function and versioning of torch objects.
--
local Foo, parent = torch.class('Foo')
Foo.__version = 1
function Foo:__init()
parent.__init(self)
end
-- serialize 'old' object
old = Foo.new()
@andreaskoepf
andreaskoepf / 2d_conv_test.lua
Last active December 24, 2015 20:38
Shows that forwad and backward operations of SpatialConvolution and SpatialFullConvolution are swapped...
require 'nn'
x = torch.rand(1,5,5)
a = nn.SpatialConvolution(1,1,3,3)
a.bias:zero()
ay1 =torch.xcorr2(x,a.weight,'V')
ay2 = a:forward(x)
b = nn.SpatialFullConvolution(1,1,3,3)
b.bias:zero()
local SpatialUnpooling, parent = torch.class('nn.SpatialUnpooling', 'nn.Module')
function SpatialUnpooling:__init(kW, kH, dW, dH, padW, padH)
parent.__init(self)
self.dW = dW or kW
self.dH = dH or kH
self.padW = padW or 0
self.padH = padH or 0
self.indices = torch.LongTensor()
self._indexTensor = torch.LongTensor()
@andreaskoepf
andreaskoepf / SpatialUnpooling.lua
Last active December 3, 2015 08:25
A simple lena-denoising auto-encoder SpatialUnpooling test.
local SpatialUnpooling, parent = torch.class('nn.SpatialUnpooling', 'nn.Module')
function SpatialUnpooling:__init(kW, kH, dW, dH, padW, padH)
parent.__init(self)
self.dW = dW or kW
self.dH = dH or kH
self.padW = padW or 0
self.padH = padH or 0
self.indices = torch.LongTensor()
self._indexTensor = torch.LongTensor()
@andreaskoepf
andreaskoepf / callbenchmark.lua
Created December 12, 2015 20:46
Performance comparison between tensor type string lookup and metatable-function selector...
x = torch.DoubleTensor()
y = torch.FloatTensor()
function testfunc(a,b)
return a + b
end
f = {}
f[x:type()] = {}
f[y:type()] = {}
require 'cunn'
--test cuda & non-cuda version
function testVolumetricFullConvolution()
local input = torch.rand(1,2,10,10,10) * 2 - 1
local a = nn.VolumetricFullConvolution(2,3, 3,3,3, 1,1,1)
local b = nn.VolumetricFullConvolution(2,3, 3,3,3, 1,1,1)
b:cuda()
b.weight = a.weight:cuda()