Skip to content

Instantly share code, notes, and snippets.

View psycharo-zz's full-sized avatar

Timur psycharo-zz

  • EPFL
  • Lausanne, Switzerland
View GitHub Profile
@psycharo-zz
psycharo-zz / theano_tf_convd2_transpose.py
Created May 24, 2017 14:48
converting theano transpose convolution filters to tensorflow format
w = w.transpose([2, 3, 1, 0])
w = w[::-1,::-1,:,:]
@psycharo-zz
psycharo-zz / feeding_runner.py
Created May 8, 2017 09:01
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-zz
psycharo-zz / tf_inputs_cityscapes.py
Created March 1, 2017 17:02
custom queue runner to read cityscapes
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-zz
psycharo-zz / tf_instance_regression.py
Last active February 3, 2017 13:07
regression masks from instance segmentation masks
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)))
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-zz
psycharo-zz / custom.js
Created June 9, 2016 08:45
jupyter python config with emacs editing mode
// 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) {
@psycharo-zz
psycharo-zz / gengmm.cpp
Created November 24, 2013 16:56
generate 1D gmm, armadillo
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;
@psycharo-zz
psycharo-zz / kmeans.h
Last active December 26, 2015 19:19
simplistic kmeans implementation
#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
@psycharo-zz
psycharo-zz / randn.h
Created October 8, 2013 11:26
generate gaussians using GSL
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);
}
@psycharo-zz
psycharo-zz / gist:6600549
Created September 17, 2013 20:59
disable dashboard on mac
defaults write com.apple.dashboard mcx-disabled -boolean YES && killall Dock