Skip to content

Instantly share code, notes, and snippets.

use libc::{c_long, size_t};
use std::c_str::CString;
pub use base::{PyObject, ToPyType, FromPyType, PyState, PyIterator};
pub use ffi::{PythonCAPI, PyObjectRaw};
pub use base::{PyError,
FromTypeConversionError,
ToTypeConversionError,
NullPyObject};
macro_rules! prim_pytype (
@lukemetz
lukemetz / image_scatter.py
Created August 26, 2015 17:58
Image tsne scatter plot
from tsne import bh_sne
import numpy as np
from skimage.transform import resize
from matplotlib import pyplot as plt
def gray_to_color(img):
if len(img.shape) == 2:
img = np.dstack((img, img, img))
return img
import theano
from theano import tensor as T
import numpy as np
from theano.sandbox.cuda.dnn import dnn_conv
from theano.sandbox.cuda import host_from_gpu
from contexttimer import Timer
import theano.compile.mode
import theano.printing
def speed_test(_func, input_shape):
@lukemetz
lukemetz / batchnorm_function.py
Last active March 21, 2016 19:53
tensorflow speed benchmark
# modified from slim
@scopes.add_arg_scope
def batch_norm(inputs,
decay=0.999,
scale=False,
epsilon=0.001,
moving_vars='moving_vars',
activation=None,
is_training=True,
trainable=True,
import tensorflow as tf
import numpy as np
from tensorflow.python import gen_batchnorm_training_op
with tf.device("/gpu:1"):
def tf_bn(shape, data_format):
""" output tensor for tensorflow implemented batch norm"""
data = np.random.randn(*shape)*10 + 5
inp = tf.Variable(data.astype("float32"), tf.float32)
import subprocess
import time
import os
OUTPUT = os.path.expanduser("~/luke_output_network")
num_per_file = 1000
try:
os.makedirs(OUTPUT)
except:
print("dir already exists. continuing")