Skip to content

Instantly share code, notes, and snippets.

@benanne
benanne / gist:2343378
Created April 9, 2012 13:23
theano GPU convolution error reproduction
import theano
import theano.tensor as T
import numpy as np
def local_feature_extractor(x, W, b, shape_info=None):
xr = x.dimshuffle(0, 2, 'x', 1) # in: (num_examples, num_input_features, 1, num_timesteps)
Wr = W.dimshuffle(0, 1, 'x', 2) # filters: (num_output_features, num_input_features, 1, width)
# the output of the convolution should be equal in length to the input
len_left = (Wr.shape[3] - 1) / 2
@benanne
benanne / gist:2889661
Created June 7, 2012 16:00
Count number of users in the MSD challenge visible evaluation triplets file
s = set()
with open("kaggle_visible_evaluation_triplets.txt", 'r') as f:
for line in f:
user, _, _ = line.strip().split('\t')
s.add(user)
print "%d users" % len(s)
@benanne
benanne / gist:3087845
Created July 11, 2012 03:38
torch7 cuda compilation error
[ 96%] Building NVCC (Device) object extra/cuda/lib/THC/CMakeFiles/THC.dir//./THC_generated_THC.cu.o
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ext/atomicity.h(48): error: identifier "__atomic_fetch_add" is undefined
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ext/atomicity.h(52): error: identifier "__atomic_fetch_add" is undefined
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/limits(1405): error: identifier "__int128" is undefined
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/limits(1409): error: identifier "__int128" is undefined
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/limits(1412): error: identifier "__int128" is undefined
@benanne
benanne / gist:3274371
Created August 6, 2012 13:10
mel spectrograms
import numpy as np
def freq2mel(freq):
return 1127.01048 * np.log(1 + freq / 700.0)
def mel2freq(mel):
return (np.exp(mel / 1127.01048) - 1) * 700
def mel_binning_matrix(specgram_window_size, sample_frequency, num_mel_bands):
@benanne
benanne / gist:8752270
Last active April 30, 2017 14:30
buffered threaded generator
import threading
import Queue
import time
def buffered_gen(source_gen, buffer_size=2, sleep_time=1):
"""
Generator that runs a slow source generator in a separate thread.
buffer_size: the maximal number of items to pre-generate (length of the buffer)
"""
buffer = Queue.Queue(maxsize=buffer_size)
@benanne
benanne / gist:8761111
Last active August 29, 2015 13:55
Generator that runs a slow source generator in a separate process.
import time
import multiprocessing as mp
def buffered_gen_mp(source_gen, buffer_size=2, sleep_time=1):
"""
Generator that runs a slow source generator in a separate process.
buffer_size: the maximal number of items to pre-generate (length of the buffer)
"""
buffer = mp.Queue(maxsize=buffer_size)
@benanne
benanne / consider_constant.py
Created February 25, 2014 16:12
Theano consider constant op
import theano
import theano.tensor as T
from theano.tensor.opt import register_canonicalize
class ConsiderConstant(theano.compile.ViewOp):
def grad(self, args, g_outs):
return [T.zeros_like(g_out) for g_out in g_outs]
consider_constant = ConsiderConstant()
register_canonicalize(theano.gof.OpRemove(consider_constant), name='remove_consider_constant')
@benanne
benanne / cufftop.py
Created April 10, 2014 19:25
CuFFT op for Theano based on scikits.cuda.fft
import numpy as np
import theano
import theano.misc.pycuda_init
import theano.sandbox.cuda as cuda
from theano.misc.pycuda_utils import to_gpuarray, to_cudandarray
from scikits.cuda import fft
@benanne
benanne / convolutional_mlp_fft.py
Created June 6, 2014 14:40
convnet from the deep learning tutorials with conv2d_fft
"""This tutorial introduces the LeNet5 neural network architecture
using Theano. LeNet5 is a convolutional neural network, good for
classifying images. This tutorial shows how to build the architecture,
and comes with all the hyper-parameters you need to reproduce the
paper's MNIST results.
This implementation simplifies the model in the following ways:
- LeNetConvPool doesn't implement location-specific gain and bias parameters
@benanne
benanne / gist:4128e5998122295f992b
Created August 27, 2014 15:13
cublasSgemm bug, CUDA 6.0
* GeForce GTX 780Ti "Superclocked"
* drivers 340.24
* CUDA 6.0
sander@sander-precision:~/tmp/schluter/Theano$ for x in full valid subsample grads; do cuda-memcheck nosetests theano/sandbox/cuda/tests/test_conv_cuda_ndarray.py:test_gemm_$x; done
========= CUDA-MEMCHECK
Using gpu device 0: GeForce GTX 780 Ti
========= Invalid __global__ read of size 4
========= at 0x000000e0 in sgemm_sm_heavy_nt_ldg