Skip to content

Instantly share code, notes, and snippets.

View szagoruyko's full-sized avatar

Sergey Zagoruyko szagoruyko

View GitHub Profile
require 'xlua'
require 'sys'
local batches_folder = '/opt/rocks/cifar.torch/cifar-10-batches-t7'
local data = {}
local labels = {}
for i=1,5 do
local name = paths.concat(batches_folder, 'data_batch_'..i..'.t7')
require 'optim'
require 'image'
require 'xlua'
require 'cudnn'
local json = require 'cjson'
local tnt = require 'torchnet'
local utils = require 'models.utils'
-- local tds = require 'tds'
local iterm = require 'iterm'
from pathlib import Path
from tqdm import tqdm
import subprocess as sp
import multiprocessing as mp
def convert(nef):
jpg = nef.with_suffix('.JPG')
n = str(nef)
command0 = f'sips -s format jpeg {nef} --out {jpg}'

Sparse tensors for Torch7

All types torch.DoubleTensor, torch.FloatTensor, etc. should have their sparse variants: torch.SparseDoubleTensor, torch.SparseFloatTensor, etc.

Copying between dense and sparse matrix should be done with :copy() function.

Underlying BLAS has to be swappable with MKL/OpenBLAS/Atlas, etc. Other math operations have to implemented with CSPARSE.

-- 2014 Sergey Zagoruyko, ENPC-UPEM, IMAGINE, Paris
-- Creates a t7 file from local image patches dataset
-- http://www.cs.ubc.ca/~mbrown/patchdata/patchdata.html
-- usage:
-- th create_dataset_file.lua *dataset_name*
-- where dataset_name is notredame, liberty or yosemite
-- which is also a folder with the same name, containing:
-- info.txt, m_50_500000_500000_0.txt and 1024x1024 bmp images
-- saves data.t7 file in the corresponding folder
require 'sys'
require 'xlua'
require 'sys'
local matio = require 'matio'
local data = {}
local labels = {}
local train_data = matio.load'./cifar-100-matlab/train.mat'
local test_data = matio.load'./cifar-100-matlab/test.mat'
@szagoruyko
szagoruyko / vgg.lua
Last active September 11, 2017 08:32
require 'nn'
local vgg = nn.Sequential()
-- building block
local function ConvBNReLU(nInputPlane, nOutputPlane)
vgg:add(nn.SpatialConvolution(nInputPlane, nOutputPlane, 3,3, 1,1, 1,1))
vgg:add(nn.SpatialBatchNormalization(nOutputPlane,1e-3))
vgg:add(nn.ReLU(true))
return vgg
end

Setting up cron to clear page cache periodically

This is usefull for ImageNet training when it loads a ton of images which are kept in page memory until training starts to lag.

Assume we are on Ubuntu.

First, create a cron job from root:

sudo crontab -e
@szagoruyko
szagoruyko / torch-opencv-blogpost.md
Last active May 30, 2017 16:52 — forked from shrubb/torch-opencv-blogpost.md
"OpenCV bindings" post for Torch blog

OpenCV Bindings for Torch

The OpenCV library implements tons of useful image processing and computer vision algorithms, as well as the high-level GUI API. Written in C++, it has bindings in Python, Java, MATLAB/Octave, C#, Perl and Ruby. We present the Lua bindings that are based on Torch, made by VisionLabs with support from Facebook and Google Deepmind.

By combining OpenCV with scientific computation abilities of Torch, one gets an even more powerful framework capable of handling computer vision routines (e.g. face detection), interfacing video streams (including cameras), easier data visualization, GUI interaction and many more. In addition, most of the computationally intensive algorithms are available on GPU via Cutorch. All these features may be essentially useful for those dealing with deep learning applied to images.

Usage Examples