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) | |
--[[ | |
Convert Linear modules to convolution modules. | |
Arguments |
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
m.updateGradInput = function(self,i,o) end -- for the gradInput | |
m.accGradParameters = function(self,i,o) end -- for freezing the parameters |
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
local function mysplit(inputstr, sep) | |
-- split strings by any type of separator | |
if sep == nil then | |
sep = "%s" | |
end | |
local t={} ; i=1 | |
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
t[i] = str | |
i = i + 1 | |
end |
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
-- Available torch7 pre-trained models for download | |
Alexnet (trained by me) | |
cudnn: https://ln.sync.com/dl/3d9c28e80#cvjp4mjs-mc2y8jrt-9wq5yebx-yrdchcei | |
mean = {0.48037518790839, 0.45039056120456, 0.39922636057037} | |
std = {0.27660147027775, 0.26883440068399, 0.28014687231841} | |
img size: 3x224x224 | |
overfeat: https://github.com/jhjin/overfeat-torch | |
mean = {118.380948, 118.380948, 118.380948} |
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
function save_configs(filename, opt) | |
-- prints the contents of a table into a file | |
local function table_print (tt, indent, done) | |
done = done or {} | |
indent = indent or 0 | |
if type(tt) == "table" then | |
local sb = {} | |
for key, value in pairs (tt) do | |
table.insert(sb, string.rep (" ", indent)) -- indent it |
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
-- multiple learning rates per network. Optimizes two copies of a model network and checks if the optimization steps (2) and (3) produce the same weights/parameters. | |
require 'torch' | |
require 'nn' | |
require 'optim' | |
torch.setdefaulttensortype('torch.FloatTensor') | |
-- (1) Define a model for this example. | |
local model = nn.Sequential() | |
model:add(nn.Linear(10,20)) |
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
--[[ | |
Create a binary tree using two ways: NN containers and nn.gModule containers. | |
This example is fairly simple, and the default fully-connected layers are all | |
of size 100. However, this should also be simple to modify to allow different | |
fc layers with varying inputs/outputs if desired (for example: input a table | |
storing input+output configuration values for each of the sub-branch's level). | |
]] | |
require 'nn' | |
require 'nngraph' |
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 'image' | |
local M = {} | |
function M.Compose(transforms) | |
return function(input) | |
for _, transform in ipairs(transforms) do | |
input = transform(input) | |
end | |
return input |
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
function mpii_convert_json( ) | |
% convert mpii annotations .mat file to .json | |
%% load annotation file | |
fprintf('Load annotations... ') | |
data = load('/media/HDD2/Datasets/Human_Pose/mpii/mpii_human_pose_v1_u12_2/mpii_human_pose_v1_u12_1.mat'); | |
fprintf('Done.\n') | |
%% open file | |
fprintf('Open file mpii_human_pose_annotations.json\n') |
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
model.modules[1].parameters = function() return nil end -- freezes the layer when using optim | |
model.modules[1].accGradParameters = function() end -- overwrite this to reduce computations |
OlderNewer