Skip to content

Instantly share code, notes, and snippets.

Timur psycharo

View GitHub Profile
def read_obj(fname, max_degree=6, dtype=np.float32):
Reads a mesh from an obj file.
Faces are converted into triangles.
fname: path or file-like object
max_degree: maximum degree for the adjacency
dtype: type for the vertex array
(verts, faces)
psycharo /
Created Feb 6, 2018
tensorflow implementation of permutohedral filtering
# 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],
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?
psycharo /
Last active Feb 6, 2018
permutohedral lattice filtering in numpy
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],
weighted_inputs = weighted_inputs.reshape([-1, V])
## sum up at corresponding indices (update with duplicatess)
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))
psycharo /
Created May 24, 2017
converting theano transpose convolution filters to tensorflow format
w = w.transpose([2, 3, 1, 0])
w = w[::-1,::-1,:,:]
psycharo /
Created May 8, 2017
custom multi-threading runner for tensorflow
import threading
import numpy as np
import tensorflow as tf
class FeedingRunner(object):
"""Takes care of feeding/dequeueing data into the queue
Based on tf.train.QueueRunner
def __init__(self, generator, dtypes, shapes, names, num_threads,
psycharo /
Created Mar 1, 2017
custom queue runner to read cityscapes
def instance_to_regression_map(instances, cids):
"""Convert instance label map to the regression map
instances: instance label mask
cids: ids of classes to load
# TODO: for all the classes that have instances, we can compute this
image_size = instances.shape[:2]
reg = np.zeros(image_size + (4,), dtype=np.uint16)
# instead of this, we can simply ???
psycharo /
Last active Feb 3, 2017
regression masks from instance segmentation masks
def _next_instance(mask, iid, instances):
"""Process single instance and add it to the mask
mask: source mask
iid: instance id
instances: instance segmentation mask
updated mask
yx = tf.to_int32(tf.where(tf.equal(instances, iid)))
class ImageCoder(object):
"""Helper class for handling images in TensorFlow."""
def __init__(self, channels=3, config=None):
# Create a single TensorFlow Session for all image decoding calls.
self._sess = tf.Session(config=config)
# TensorFlow ops for JPEG decoding.
self._src_png = tf.placeholder(dtype=tf.string)
self._dst_raw = tf.image.decode_png(self._src_png, channels=channels)
psycharo /
Created Jan 23, 2017
example of an efficient and simple input pipeline in tensorflow
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()
You can’t perform that action at this time.