Skip to content

Instantly share code, notes, and snippets.

View keunwoochoi's full-sized avatar

Keunwoo Choi keunwoochoi

View GitHub Profile
@keunwoochoi
keunwoochoi / freesound_crawler.py
Last active July 11, 2020 06:38
how to crawl freesound
# Keunwoo Choi
# This example crawl snoring sound by searching keyword 'snore'.
from __future__ import print_function
import freesound # $ git clone https://github.com/MTG/freesound-python
import os
import sys
api_key = 'YOUR_API_KEY'
folder = 'data_freesound/' # folder to save
def gen():
print('generator initiated')
idx = 0
while True:
yield x_train[:32], y_train[:32]
print('generator yielded a batch %d' % idx)
idx += 1
tr_gen = gen()
model.fit_generator(generator=tr_gen, steps_per_epoch=20, max_queue_size=10)
import time
def gen():
print('generator initiated')
idx = 0
while True:
yield x_train[:32], y_train[:32]
print('generator yielded a batch %d' % idx)
idx += 1
time.sleep(3)
def gen():
print('generator initiated')
idx = 0
while True:
yield x_train[:32], y_train[:32]
print('generator yielded a batch %d' % idx)
idx += 1
tr_gen = gen()
model.fit_generator(generator=tr_gen, steps_per_epoch=20, max_queue_size=10,
import threading
class threadsafe_iter:
"""Takes an iterator/generator and makes it thread-safe by
serializing call to the `next` method of given iterator/generator.
"""
def __init__(self, it):
self.it = it
self.lock = threading.Lock()
@keunwoochoi
keunwoochoi / get_ismir2017_paper.py
Created October 6, 2017 02:43
Run it to get all ismir 2017 papers.
links = '''https://ismir2017.smcnus.org/wp-content/uploads/2017/10/126_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/79_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/89_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/119_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/51_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/85_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/164_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/220_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/172_Paper.pdf
https://ismir2017.smcnus.org/wp-content/uploads/2017/10/180_Paper.pdf
@keunwoochoi
keunwoochoi / unet.py
Created October 11, 2017 00:49
Keras-unet
import keras
from keras import backend as K
from keras.layers.convolutional import Conv2D, Conv2DTranspose
from keras.layers import Input, Dense, Activation
from keras.layers import concatenate # functional interface
from keras.models import Model
from keras.layers.advanced_activations import LeakyReLU
N_INPUT = 512
@keunwoochoi
keunwoochoi / BN_test_time.py
Last active November 30, 2017 15:33
Simple batch normalization prediction fix for Keras 1.x weights
import keras.backend as K
# Load the weights
# If there are more than 1 BN, you might wanna have a proper layer
moving_mean = f['batchnormalization_1_running_mean']
moving_std = f['batchnormalization_1_running_std']
beta = f['batchnormalization_1_beta']
gamma = f['batchnormalization_2_beta']
# BE CAREFUL! Keras 1 stores std
@keunwoochoi
keunwoochoi / kapre_debug.py
Created December 8, 2017 14:56
to debug kapre's spectrogram. copied from ipython notebook.
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import numpy as np
import librosa
import keras
from keras import backend as K
print(keras.__version__)
print('Keras backend: ', keras.backend._BACKEND, ' and image dim ordering: ', keras.backend.image_dim_ordering())
@keunwoochoi
keunwoochoi / speech.py
Created March 28, 2018 12:47
synthesize_formant_speech.py
"""
Code converted by Keunwoo from https://ccrma.stanford.edu/~jos/fp/Formant_Filtering_Example.html (JOS)
"""
import numpy as np
import scipy.signal as signal
import librosa
def gen_speech(F, sig=None, filename='speech'):
nsecs = len(F)