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
// convert an OpenCV multi-channel matrix to Armadillo cube. A copy is made | |
template <typename T, int NC> | |
Cube<T> to_arma(const cv::Mat_<cv::Vec<T, NC>> &src) | |
{ | |
vector<cv::Mat_<T>> channels; | |
Cube<T> dst(src.cols, src.rows, NC); | |
for (int c = 0; c < NC; ++c) | |
channels.push_back({src.rows, src.cols, dst.slice(c).memptr()}); | |
cv::split(src, channels); | |
return dst; |
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 mmul(*tensors): | |
return tf.foldl(tf.matmul, tensors) | |
def msym(X): | |
return (X + tf.matrix_transpose(X)) / 2 | |
def mdiag(X): | |
return tf.matrix_diag(tf.matrix_diag_part(X)) | |
@tf.RegisterGradient('Svd') |
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
n_masks = 100 | |
n_channels = 100 | |
# do not sample more masks than this | |
n_max_samples = 50 | |
target_corr = 0.1 | |
target_corr_eps = 1.0e-2 | |
rate = target_corr |
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
def read_obj(fname, max_degree=6, dtype=np.float32): | |
''' | |
Reads a mesh from an obj file. | |
Faces are converted into triangles. | |
Arguments: | |
fname: path or file-like object | |
max_degree: maximum degree for the adjacency | |
dtype: type for the vertex array | |
Returns: | |
(verts, faces) |
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
# now, let's do tf implementation | |
def ph_splat(inputs, offsets, weights, nbs): | |
N, C = inputs.shape | |
F = weights.shape[1] - 1 | |
M = nbs.shape[0] | |
weighted_inputs = tf.matmul(weights[:N,:,tf.newaxis], | |
inputs[:N,tf.newaxis,:]) | |
weighted_inputs = tf.reshape(weighted_inputs, [-1, C]) | |
idxs = tf.reshape(offsets[:N,:F+1], [-1,1])+1 | |
# TODO: the only thing is the unknown shape of M? |
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 np_splat(inputs, offsets, weights, nbs): | |
N, V = inputs.shape | |
F = weights.shape[1] - 1 | |
M = nbs.shape[0] | |
# splatting | |
## compute inputs multiplied by the weights | |
weighted_inputs = np.matmul(weights[:N,:,np.newaxis], | |
inputs[:N,np.newaxis,:]) | |
weighted_inputs = weighted_inputs.reshape([-1, V]) | |
## sum up at corresponding indices (update with duplicatess) |
NewerOlder