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
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
# 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) |
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
w = w.transpose([2, 3, 1, 0]) | |
w = w[::-1,::-1,:,:] |
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 | |
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, |
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 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 ??? |
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 _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))) |
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
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) |
NewerOlder