Skip to content

Instantly share code, notes, and snippets.

@mdfirman
mdfirman / 2dto3d.py
Last active June 30, 2017 11:12
Training a 2d -> 3d network
# 2D -> 3D bottleneck architecture
import tensorflow as tf
layers = tf.contrib.slim.layers
# Network inputs
x_in = tf.placeholder(tf.float32, shape=(None, 64, 64, 3))
y_in = tf.placeholder(tf.float32, shape=(None, 32, 32, 32, 1))
phase = tf.placeholder(tf.bool) # for batch norm - see http://ruishu.io/2016/12/27/batchnorm/
@mdfirman
mdfirman / 0_reuse_code.js
Created April 11, 2017 09:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mdfirman
mdfirman / lasagne_minibatch_discrimination.py
Created October 20, 2016 14:04
A lasagne layer to perform minibatch discrimination
class MinibatchDiscrimination(lasagne.layers.Layer):
'''
A lasagne layer to perform minibatch discrimination [1]. The idea is to improve
generative advesarial networks (GANs) by appending a feature to each input example
which takes information from all the other items in the minibatch.
This means that the generator, when it comes to creating a new minibatch, is less
likely to fixate on one point. Instead it should be incentivised to generate
examples covering the full output space.
Notation and formulation as described in [1], section 3.2
@mdfirman
mdfirman / codestats.py
Last active April 8, 2016 17:17
Script to recursively count lines of code in files in folder
#!/usr/bin/python
# Script which prints statistics about number of lines from all the files
# recursively below the current folder.
# Currently just looks at .py and .ipynb files, but could be trivially modified
# to look at other file types.
# Caveat: Includes comments, blank lines etc in the count.
# Bash solution:
# #! /bin/sh
# find . -name '*.py' | xargs wc -l
@mdfirman
mdfirman / io_mat_large.py
Last active October 20, 2016 14:07
Saving python dictionaries containing arbitrarily large numpy arrays --- a hacky fix for python 2.7 problem
import numpy as np
import scipy
def savemat_large(savepath, dic, modify_in_place=True, **kwargs):
"""
Save a python dictionaries containing arbitrarily large numpy arrays.
Essentially a wrapper for scipy.io.savemat, but first numpy arrays which
are too large are split up.
This is a hacky fix for the problem that individual objects bigger than
# https://help.github.com/articles/merging-an-upstream-repository-into-your-fork/
git pull https://github.com/groakat/engaged_hackathon.git master