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 threading | |
def _int64_feature(value): | |
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) | |
def _bytes_feature(value): | |
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) | |
def _convert_example(rgb_path, label_path): | |
# rgb_png = tf.gfile.GFile(rgb_path, 'rb').read() |
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
def pdist(X): | |
""" | |
Computes pairwise distance between each pair of points | |
Args: | |
X - [N,D] matrix representing N D-dimensional vectors | |
Returns: | |
[N,N] matrix of (squared) Euclidean distances | |
""" | |
x2 = tf.reduce_sum(X * X, 1, True) | |
return x2 - 2 * tf.matmul(X, tf.transpose(X)) + tf.transpose(x2) |
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
// register a callback when the IPython.notebook instance is created. | |
$([IPython.events]).on('app_initialized.NotebookApp', function(){ | |
function to(mode) { | |
// this can be either 'vim' or 'emacs' | |
var mode = mode || 'emacs'; | |
// first let's apply mode to all current cells | |
function to_mode(c) { return c.code_mirror.setOption('keyMap', mode);}; | |
var cells = IPython.notebook.get_cells(); | |
if (cells != null) { |
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 | |
def softmax(x, axis=None): | |
e_x = np.exp(x - np.max(x, axis=axis, keepdims=True)) | |
return e_x / np.sum(e_x, axis=axis, keepdims=True) |
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
vector<cv::Mat> gradient_histogram(const cv::Mat &M, const cv::Mat &O, int num_channels) | |
{ | |
vector<cv::Mat> channels; | |
double step = 2 * M_PI / num_channels; | |
for (int t = 0; t < num_channels; ++t) | |
{ | |
cv::Mat C; | |
cv::inRange(O, t*step, t*step+1, C); | |
C.convertTo(C, CV_64F); | |
C /= 255.0; |
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
inline arma::mat integral_image(const arma::mat &a) | |
{ | |
using namespace arma; | |
mat a_ii = zeros(a.n_rows+1, a.n_cols+1); | |
for (size_t j = 0; j < a.n_rows; ++j) | |
{ | |
double sum = 0.0; | |
for (size_t i = 0; i < a.n_cols; ++i) | |
{ | |
sum += a(j,i); |
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
map<double, size_t> top; | |
size_t max_size = 100; | |
auto top_add = [&top,max_size](double value, size_t id) | |
{ | |
if (top.size() < max_size) | |
top.insert(make_pair(value, id)); | |
else | |
{ | |
if (top.begin()->first < value) |
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
def loadmat(filename): | |
''' | |
this function should be called instead of direct spio.loadmat | |
as it cures the problem of not properly recovering python dictionaries | |
from mat files. It calls the function check keys to cure all entries | |
which are still mat-objects | |
''' | |
data = sio.loadmat(filename, struct_as_record=False, squeeze_me=True) | |
return _check_keys(data) |
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
def read_seq(path): | |
def read_header(ifile): | |
feed = ifile.read(4) | |
norpix = ifile.read(24) | |
version = struct.unpack('@i', ifile.read(4)) | |
length = struct.unpack('@i', ifile.read(4)) | |
assert(length != 1024) | |
descr = ifile.read(512) | |
params = [struct.unpack('@i', ifile.read(4))[0] for i in range(0,9)] |
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
string string_format(const string fmt, ...) | |
{ | |
int size = 512; | |
std::string str; | |
va_list ap; | |
while (1) { | |
str.resize(size); | |
va_start(ap, fmt); | |
int n = vsnprintf((char *)str.c_str(), size, fmt.c_str(), ap); |