This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy | |
import sys | |
import timeit | |
try: | |
import numpy.core._dotblas | |
print 'FAST BLAS' | |
except ImportError: | |
print 'slow blas' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |