Skip to content

Instantly share code, notes, and snippets.

View szagoruyko's full-sized avatar

Sergey Zagoruyko szagoruyko

View GitHub Profile
@szagoruyko
szagoruyko / nvsmi
Created February 7, 2015 01:04
Nicer nvidia-smi output for GeForce cards
#!/usr/bin/env python
import subprocess
import re
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
@szagoruyko
szagoruyko / gist:b6e70f6c6be9a8399c10
Last active August 29, 2015 14:15
removeDescriptors
function removeDescriptors(net)
for i,val in pairs(net.modules) do
if tostring(val):find('cudnn') then
for name,field in pairs(val) do
if name:find('Desc') then
val[name] = nil
end
end
val.algType = nil
val.iDesc = nil
Using 1-th gpu
Loading ./data/ptb.train.txt, size of data = 929589
Loading ./data/ptb.valid.txt, size of data = 73760
Loading ./data/ptb.test.txt, size of data = 82430
Network parameters:
{
layers : 2
lr : 1
max_max_epoch : 13
max_grad_norm : 5
Using 1-th gpu
Loading ./data/ptb.train.txt, size of data = 929589
Loading ./data/ptb.valid.txt, size of data = 73760
Loading ./data/ptb.test.txt, size of data = 82430
Network parameters:
{
layers : 2
lr : 1
max_max_epoch : 13
max_grad_norm : 5
-- a script to simplify trained net by incorporating every SpatialBatchNormalization to SpatialConvolution
-- and BatchNormalization to Linear
local function BNtoConv(net)
for i,v in ipairs(net.modules) do
if v.modules then
BNtoConv(v)
else
if torch.typename(v) == 'nn.SpatialBatchNormalization' and
(torch.typename(net:get(i-1)):find'SpatialConvolution') then
@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
@szagoruyko
szagoruyko / gist:6da251c360340cd3c48a
Created June 11, 2015 13:43
BidirectionalSequencer.lua
local BidirectionalSequencer, parent = torch.class('nn.BidirectionalSequencer', 'nn.Container')
function BidirectionalSequencer:__init(module_forward, module_backward, nOutputSize)
parent.__init(self)
self.module_forward = module_forward
self.module_backward = module_backward
self.modules[1] = nn.Sequencer(module_forward)
self.modules[2] = nn.Sequencer(module_backward)
self.output = {}
-- Usage:
-- find . -name model.net -print0 | xargs -0 -n 1 th ~/clearState.lua
require 'cudnn'
local name = arg[1]
assert(paths.filep(name))
print'before'
require 'cv.highgui'
require 'cv.videoio'
require 'cv.imgproc'
require 'nn'
--require 'clnn'
local cap = cv.VideoCapture{device=0}
if not cap:isOpened() then
print("Failed to open the default camera")
os.exit(-1)
function nn.Module:replace(callback)
local out = callback(self)
if self.modules then
for i, module in ipairs(self.modules) do
self.modules[i] = module:replace(callback)
end
end
return out
end