Skip to content

Instantly share code, notes, and snippets.

Timur psycharo

Block or report user

Report or block psycharo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View mesh_io.py
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)
@psycharo
psycharo / tf_permutohedral.py
Created Feb 6, 2018
tensorflow implementation of permutohedral filtering
View tf_permutohedral.py
# 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?
@psycharo
psycharo / np_permutohedral.py
Last active Feb 6, 2018
permutohedral lattice filtering in numpy
View np_permutohedral.py
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)
View tf_svd_gradient.py
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')
@psycharo
psycharo / theano_tf_convd2_transpose.py
Created May 24, 2017
converting theano transpose convolution filters to tensorflow format
View theano_tf_convd2_transpose.py
w = w.transpose([2, 3, 1, 0])
w = w[::-1,::-1,:,:]
@psycharo
psycharo / feeding_runner.py
Created May 8, 2017
custom multi-threading runner for tensorflow
View feeding_runner.py
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
psycharo / tf_inputs_cityscapes.py
Created Mar 1, 2017
custom queue runner to read cityscapes
View tf_inputs_cityscapes.py
def instance_to_regression_map(instances, cids):
"""Convert instance label map to the regression map
Args:
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
psycharo / tf_instance_regression.py
Last active Feb 3, 2017
regression masks from instance segmentation masks
View tf_instance_regression.py
def _next_instance(mask, iid, instances):
"""Process single instance and add it to the mask
Args:
mask: source mask
iid: instance id
instances: instance segmentation mask
Returns:
updated mask
"""
yx = tf.to_int32(tf.where(tf.equal(instances, iid)))
View tf_imagecoder.py
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
psycharo / tf_inputs.py
Created Jan 23, 2017
example of an efficient and simple input pipeline in tensorflow
View tf_inputs.py
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.