Skip to content

Commit

Permalink
use replace from nn
Browse files Browse the repository at this point in the history
  • Loading branch information
szagoruyko committed May 26, 2016
1 parent 9a5c2f0 commit 3ee0de9
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions convert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,10 @@ local layer_list = {
'VolumetricAveragePooling',
}

-- similar to nn.Module.apply
-- goes over a net and recursively replaces modules
-- using callback function
local function replace(self, callback)
local out = callback(self)
if self.modules then
for i, module in ipairs(self.modules) do
self.modules[i] = replace(module, callback)
end
end
return out
end

-- goes over a given net and converts all layers to dst backend
-- for example: net = cudnn.convert(net, cudnn)
function cudnn.convert(net, dst)
return replace(net, function(x)
return net:replace(function(x)
local y = 0
local src = dst == nn and cudnn or nn
local src_prefix = src == nn and 'nn.' or 'cudnn.'
Expand Down

2 comments on commit 3ee0de9

@alexwal
Copy link

@alexwal alexwal commented on 3ee0de9 Jun 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[solved, see szagoruyko's comment]
calling replace on arbitrary net results in the following error:

/home/ubuntu/torch/install/share/lua/5.1/cudnn/convert.lua:59: attempt to call method 'replace' (a nil value)
stack traceback:
    /home/ubuntu/torch/install/share/lua/5.1/cudnn/convert.lua:59: in function 'convert'
    [string "_RESULT={cudnn.convert(net, cudnn)}"]:1: in main chunk
    [C]: in function 'xpcall'
    /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
    ...untu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
    [C]: at 0x00406670  

@szagoruyko
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update nn:

luarocks install nn

Please sign in to comment.