Skip to content

Instantly share code, notes, and snippets.

View drscotthawley's full-sized avatar
Solving environment /

Scott H. Hawley drscotthawley

Solving environment /
View GitHub Profile
@drscotthawley
drscotthawley / grpc.patch
Last active October 19, 2021 04:36
Patch for GRPC to work with tensorflow, created from main grpc/ directory
diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc
index 561276f0c2..1af0935e1f 100644
--- a/src/core/lib/gpr/log_linux.cc
+++ b/src/core/lib/gpr/log_linux.cc
@@ -40,7 +40,7 @@
#include <time.h>
#include <unistd.h>
-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_sys_gettid); }
@drscotthawley
drscotthawley / inst_freq.py
Last active November 4, 2019 18:21
Alternative method for calculating "instantaneous frequency" for use with spectrograms.
#! /usr/bin/env python3
# Test script for Phase 'Unrolling' / Instantaneous frequency
#
# See Jesse Engel's "rainbowgrams" script, https://gist.github.com/jesseengel/e223622e255bd5b8c9130407397a0494
#
# Modifications by Scott H. Hawley, @drscotthawley and Billy Mitchell
# These modified versions seem to be both more accurate (~2000x less reconstruction error)
# and faster (>20%)
#
# note, to really see/hear the difference, change dtypes to np.float16!
@drscotthawley
drscotthawley / proc_fma.py
Last active August 22, 2019 06:23
FMA dataset conversion script, genre classification, to individual subdirs
#! /usr/env/python3
#
# FMA conversion script, genre classification
# Author: Scott Hawley
# License: Do as you like
#
# For FMA dataset https://github.com/mdeff/fma
# to be used with panotti https://github.com/drscotthawley/panotti
#
# This will create a directory called Samples/
@drscotthawley
drscotthawley / osc2wek.py
Last active April 23, 2019 03:17
Sends incoming OSC messages (subject to some filter) to Wekinator
#! /usr/bin/env python3
'''
osc2wek.py
Author: Scott Hawley
This listens for incoming OSC messages and sends them on to Wekinator
Steps to get running (in Terminal):
0. First you need Mercurial "hg". It might be installed by default.
1. Use hg to clone the grail osc code:
@drscotthawley
drscotthawley / get_1cycle_schedule.py
Last active May 31, 2022 16:51
Implementation of 1cycle learning rate schedule, but without fast.ai
import numpy as np
def get_1cycle_schedule(lr_max=1e-3, n_data_points=8000, epochs=200, batch_size=40, verbose=0):
"""
Creates a look-up table of learning rates for 1cycle schedule with cosine annealing
See @sgugger's & @jeremyhoward's code in fastai library: https://github.com/fastai/fastai/blob/master/fastai/train.py
Wrote this to use with my Keras and (non-fastai-)PyTorch codes.
Note that in Keras, the LearningRateScheduler callback (https://keras.io/callbacks/#learningratescheduler) only operates once per epoch, not per batch
So see below for Keras callback
@drscotthawley
drscotthawley / FastAICustomModelExample.ipynb
Created November 20, 2018 06:57
FastAICustomModelExample
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drscotthawley
drscotthawley / text_shortener.py
Last active August 27, 2020 20:31
Shorten text by applying various shortening rules
#!/usr/bin/env python
# Replaces lengthy words/phrases with shorter variants
# Author: Scott Hawley
import pandas as pd
import re
import os
@drscotthawley
drscotthawley / scope_with_trigger.py
Last active May 3, 2018 03:42
Realtime waveform display with tunable trigger level
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'Scott H. Hawley'
__copyright__ = 'Scott H. Hawley'
__license__ = "MIT Licence (do what you want, don't blame me)"
import numpy as np
import cv2
import soundcard as sc # https://github.com/bastibe/SoundCard
from scipy.ndimage.interpolation import shift
@drscotthawley
drscotthawley / oscilloscope.py
Last active May 3, 2023 19:02
Realtime oscilloscope in 20 lines of Python, via soundcard & OpenCV
import numpy as np
import cv2
import soundcard as sc # Get it from https://github.com/bastibe/SoundCard
imWidth, imHeight = 1024, 512 # screen size
def draw_wave(screen, mono_audio, xs, title="oscilloscope", gain=5):
screen *= 0 # clear the screen
ys = imHeight/2*(1 - np.clip( gain * mono_audio[0:len(xs)], -1, 1)) # the y-values of the waveform
pts = np.array(list(zip(xs,ys))).astype(np.int) # pair up xs & ys
cv2.polylines(screen,[pts],False,(0,255,0)) # connect points w/ lines
cv2.imshow(title, screen) # show what we've got
@drscotthawley
drscotthawley / apply_sox_effect.py
Last active November 12, 2023 18:10
Accessing Sox Audio Effects from Python via Pysox
import pysox
import librosa
import numpy as np
def apply_sox_effect(signal, sr, fxstr):
# This writes signal to a .wav file, processes it sox to another file, loads that and returns it.
#
# signal: a numpy list of numbers; the audio signal
# sr: the sample rate in Hz, must be an integer
# fxstr: a semicolon-separated string starting with the effect name followed by parameter values in order