Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@kastnerkyle
kastnerkyle / vq.py
Last active December 21, 2015 20:19
Vector quantization experiments - DEPRECATED! See audio_tools.py
from scipy.linalg import svd
from scipy.io import wavfile
from scipy.cluster.vq import vq
from scipy.signal import firwin
import matplotlib.pyplot as plt
import numpy as np
import zipfile
import tarfile
from numpy.lib.stride_tricks import as_strided
import theano
@kastnerkyle
kastnerkyle / tf_gc.py
Last active December 21, 2015 20:20
Testing of time attack AGC - DEPRECATED! See audio_tools.py
from scipy.linalg import svd
from scipy.io import wavfile
from scipy.cluster.vq import vq
from scipy.signal import firwin
import matplotlib.pyplot as plt
import numpy as np
import zipfile
import tarfile
from numpy.lib.stride_tricks import as_strided
import theano
class SPPLayer(lasagne.layers.Layer):
def __init__(self, incoming, **kwargs):
super(SPPLayer, self).__init__(incoming, **kwargs)
# divide by 4 gives 16 patches
self.win1 = (int(np.floor(incoming.output_shape[2]/4.0)), int(np.floor(incoming.output_shape[3]/4.0)))
self.str1 = (int(np.ceil(incoming.output_shape[2]/4.0)), int(np.ceil(incoming.output_shape[3]/4.0)))
# divide by 2 gives 4 patches
self.win2 = (int(np.floor(incoming.output_shape[2]/2.0)), int(np.floor(incoming.output_shape[3]/2.0)))
@kastnerkyle
kastnerkyle / gist:8d82b4f93705e339354f
Created December 12, 2015 17:11 — forked from anonymous/gist:0a6e9ceccd30e1d5f992
Mixture of Gaussian densities, and derivatives
def gaussian_density_batch(x, mean, stddev, correlation, compute_derivatives=False):
"""
Compute the Gaussian density at x for a 2D normal distribution with parameters mean, stddev, correlation.
This works simultaneously on a batch of inputs. The inputs should have dimensions:
x.shape = (n, 1, 2)
mean.shape = stddev.shape = (n, m, 2)
correlation.shape = (n, m, 1)
where n*m is the number of different Gaussian density functions that we want to evaluate, on n input points x.
So the same input x is plugged into the density for m Gaussian pdfs. (This is convenient for evaluating a
@kastnerkyle
kastnerkyle / gaussian_windows.py
Last active February 3, 2016 02:08
An approach to Gaussian attention as per Graves' Generating Sequences with Recurrent Neural Networks
"""
bitmap utils from Shawn Tan
"""
# Author: Kyle Kastner
# License: BSD 3-clause
# Equation 46 from http://arxiv.org/abs/1308.0850
from theano import tensor
from scipy import linalg
import theano
import numpy as np
@kastnerkyle
kastnerkyle / audio_tools.py
Last active November 17, 2024 12:01
Audio tools for numpy/python. Constant work in progress.
raise ValueError("DEPRECATED/FROZEN - see https://github.com/kastnerkyle/tools for the latest")
# License: BSD 3-clause
# Authors: Kyle Kastner
# Harvest, Cheaptrick, D4C, WORLD routines based on MATLAB code from M. Morise
# http://ml.cs.yamanashi.ac.jp/world/english/
# MGC code based on r9y9 (Ryuichi Yamamoto) MelGeneralizedCepstrums.jl
# Pieces also adapted from SPTK
from __future__ import division
import numpy as np
@kastnerkyle
kastnerkyle / theaded_camera_reader.py
Last active October 26, 2020 07:43
Threaded camera reader dummy from Stack Overflow - a nice tutorial on multiprocessing in Python
# code from Stack Overflow with minor Python 3 tweaks
# Thanks to Andrew from SO for making such great code!
# http://stackoverflow.com/questions/14416130/dynamically-create-a-list-of-shared-arrays-using-python-multiprocessing
# For a reference on parallel processing in Python see this tutorial by David Beazley
# http://www.slideshare.net/dabeaz/an-introduction-to-python-concurrency
import time
import ctypes
import logging
try:
import Queue
@kastnerkyle
kastnerkyle / threaded_image_reader.py
Last active December 15, 2019 12:28
Threaded image reader in Python
# Author: Kyle Kastner
# License: BSD 3-Clause
# For a reference on parallel processing in Python see tutorial by David Beazley
# http://www.slideshare.net/dabeaz/an-introduction-to-python-concurrency
# Loosely based on IBM example
# http://www.ibm.com/developerworks/aix/library/au-threadingpython/
try:
import Queue
except ImportError:
import queue as Queue
@kastnerkyle
kastnerkyle / shared_memory_example.py
Last active April 20, 2024 22:14
Shared memory example
# Example from J.F. Sebastien on SO
# http://stackoverflow.com/questions/7894791/use-numpy-array-in-shared-memory-for-multiprocessing/7908612#7908612
import ctypes
import logging
import multiprocessing as mp
from contextlib import closing
import numpy as np
@kastnerkyle
kastnerkyle / mscoco_dataset.py
Last active July 27, 2016 15:19
MSCOCO threaded iterator/reader
# Authors: Kyle Kastner, Francesco Visin
# License: BSD 3-Clause
try:
import Queue
except ImportError:
import queue as Queue
import threading
import time
from matplotlib.path import Path
from PIL import Image