Skip to content

Instantly share code, notes, and snippets.

View taey16's full-sized avatar

Taewan Ethan Kim taey16

  • Kakao Enterprise
  • South Korea
View GitHub Profile
@taey16
taey16 / gen_seq.py
Last active October 11, 2016 04:24
min_char_rnn
import numpy as np
import sys
import scipy.io as sio
def sample(hprev, xt, n):
for index in xt:
x = np.zeros((vocab_size, 1))
x[index] = 1
h = np.tanh(np.dot(Wxh, x) + np.dot(Whh, hprev) + bh)
y = np.dot(Why, h) + by
@taey16
taey16 / predict_ilsvrc12_ResNet.py
Last active July 4, 2018 01:53
predict_ilsvrc12_ResNet.py
import numpy as np
import sys
import caffe
from caffe import caffe_utils as utils
import datetime
CAFFE_ROOT='/works/caffe/'
MODEL_DEPLOY_FILE = \
#'/storage/ImageNet/ILSVRC2012/model/resnet/ResNet_caffe_models/ResNet-50-deploy.prototxt'
@taey16
taey16 / lr_per_layer.lua
Created October 25, 2015 16:31
Assign different learning rate for a layer
-- suppose you have a model called model
lrs_model = model:clone()
lrs = lrs_model:getParameters()
lrs:fill(1) -- setting the base learning rate to 1
-- now lets set the learning rate factor of the bias of module 5 to 2
lrs_model:get(5).bias:fill(2)
-- same thing for the weights of module 2, let's set them to 3
lrs_model:get(2).weight:fill(3)
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)
#!/usr/bin/env python
import numpy
import sys
import timeit
try:
import numpy.core._dotblas
print 'FAST BLAS'
except ImportError:
print 'slow blas'
@taey16
taey16 / convert_vgg.lua
Last active August 18, 2016 09:43
convert_caffe
require 'loadcaffe'
require 'nn'
local model_root = '/storage/models/vgg'
local deploy_file = paths.concat(model_root, 'vgg_layer16_deploy.prototxt')
local weight_file = paths.concat(model_root, 'vgg_layer16.caffemodel')
local model = loadcaffe.load(deploy_file, weight_file, nn)
return model