Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nsavinov committed Sep 22, 2016
1 parent 0253bc5 commit 9a62be6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Comparing to the very commonly used data augmentation, TI-pooling finds canonica
One needs to be really sure to introduce transformation-invariance: in some real-world problems some transformation can seem like an nuisance factor, but can be in fact useful. E.g. rotation-invariance proved does not work well for natural objects, because most natural objects have a "default" orientation, which helps us to recognize them (an upside-down animal is usually harder to recognize, not only for a CNN, but also for a human being). Same rotation-invariance proved to be very useful for cell recognition, where orientation is essentially random.

Also, while training time is comparable and usually faster than with data augmentation, the testing time increases linearly with the number of transformations.

### Instructions for Linux
First run ./setup.sh to download the dataset. Then run "th rot_mnist12K.lua" to start training. The code was tested for torch commit ed547376d552346afc69a937c6b36cf9ea9d1135 (12 September 2016).
6 changes: 2 additions & 4 deletions rot_mnist12K.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require 'math'
require 'nn'
require 'cunn'
require 'image'
require 'optim'

require 'rot_mnist12K_model'
require 'tools'
Expand Down Expand Up @@ -98,10 +99,7 @@ while true do -- Cycle through the batches.
torch.save(opt.model_dump_name .. '_state', optim_state)
torch.manualSeed(epoch)
end
if (counter == 0) and (epoch % opt.decrease_step_size == 0) then
optim_state.step = optim_state.step / 2
end
-- Make a step using AdaDelta optimization algorithm (updates parameters).
convergent_adadelta(batch_feval, parameters, optim_state)
optim.adadelta(batch_feval, parameters, optim_state)
collectgarbage()
end
4 changes: 4 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
wget http://www.iro.umontreal.ca/~lisa/icml2007data/mnist_rotation_new.zip
unzip mnist_rotation_new.zip
rm mnist_rotation_new.zip
36 changes: 0 additions & 36 deletions tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-- load_rotated_mnist(file_name, count)
-- get_transformed(batch_inputs, opt)
-- calculate_error(model, data_to_check, opt)
-- convergent_adadelta(opfunc, x, config, state)

-- Loads the dataset from an .amat file.
function load_rotated_mnist(file_name, count)
Expand Down Expand Up @@ -80,38 +79,3 @@ function calculate_error(model, data_to_check, opt)
return error / data_size
end

-- Optimization subroutine: given a functional and its gradient, makes a step
-- minimizing the functional opfunc.
function convergent_adadelta(opfunc, x, config, state)
-- (0) get/update state
local state = state or {}
state.rho = state.adadelta_rho or 0.9
state.eps = state.adadelta_eps or 1e-6
state.evalCounter = state.evalCounter or 0

-- (1) evaluate f(x) and df/dx
local fx,dfdx = opfunc(x)

-- (2) parameter update
if not state.paramVariance then
state.paramVariance = torch.Tensor():typeAs(x):resizeAs(dfdx):zero()
state.paramStd = torch.Tensor():typeAs(x):resizeAs(dfdx):zero()
state.delta = torch.Tensor():typeAs(x):resizeAs(dfdx):zero()
state.accDelta = torch.Tensor():typeAs(x):resizeAs(dfdx):zero()
state.step = 1
end
state.paramVariance:mul(state.rho):addcmul(1 - state.rho,dfdx,dfdx)
state.paramStd:resizeAs(state.paramVariance):copy(state.paramVariance)
:add(state.eps):sqrt()
state.delta:resizeAs(state.paramVariance):copy(state.accDelta)
:add(state.eps):sqrt():cdiv(state.paramStd):cmul(dfdx)
x:add(-state.step, state.delta)
state.accDelta:mul(state.rho)
:addcmul(1 - state.rho, state.delta, state.delta)

-- (3) update evaluation counter
state.evalCounter = state.evalCounter + 1

-- return x*, f(x) before optimization
return x,{fx}
end

0 comments on commit 9a62be6

Please sign in to comment.