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) |
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
vec generate_gmm(size_t N, const vec &mean, const vec &stddev, const vec &weights) | |
{ | |
vec result(N); | |
const size_t K = weights.size(); | |
size_t filled = 0; | |
for (size_t k = 0; k < K; ++k) | |
{ | |
size_t size_k = weights(k) * N; | |
result.subvec(filled, filled + size_k - 1) = mean(k) + randn(size_k) * stddev(k); | |
filled += size_k; |
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
#include <cfloat> | |
#include <armadillo> | |
using namespace arma; | |
/** | |
* K-means algorithm | |
* @param K the number of clusters | |
* @param means cluster centers | |
* @param counts sizes of clusters | |
* @param resps assignments to clusters |
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
double randn(double mean, double sigma) | |
{ | |
gsl_rng *gnr = gsl_rng_alloc(gsl_rng_default); | |
return mean + gsl_ran_gaussian(gnr, sigma); | |
gsl_rng_free(gnr); | |
} |
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
defaults write com.apple.dashboard mcx-disabled -boolean YES && killall Dock |