Skip to content

Instantly share code, notes, and snippets.

💭
Solving environment -

Scott Hawley drscotthawley

View GitHub Profile
@drscotthawley
drscotthawley / get_1cycle_schedule.py
Last active Mar 29, 2019
Implementation of 1cycle learning rate schedule, but without fast.ai
View get_1cycle_schedule.py
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
View FastAICustomModelExample.ipynb
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 Jun 5, 2018
Shorten text by applying various shortening rules
View text_shortener.py
#!/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
Realtime waveform display with tunable trigger level
View scope_with_trigger.py
#! /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 17, 2018
Realtime oscilloscope in 20 lines of Python, via soundcard & OpenCV
View oscilloscope.py
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 Apr 29, 2018
Accessing Sox Audio Effects from Python via Pysox
View apply_sox_effect.py
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
@drscotthawley
drscotthawley / TestRenderMan_DexedVST.ipynb
Created Apr 28, 2018
Slight modification of RenderMan demo, made for Python 3 and MacOS
View TestRenderMan_DexedVST.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drscotthawley
drscotthawley / Gamepad_Eyes_OSC.pde
Last active Mar 7, 2018
"Gamepad" Input example for Wekinator, e.g. for Xbox 360 controller
View Gamepad_Eyes_OSC.pde
// Gamepad_Eyes_OSC: demo of using game controller for OSC input.
// Uses the two thumb-sticks and either the left or right bumper buttons.
//
// Peter Lager maintains the Game Control Plus library (for Processing),
// which provides control data for joysticks and other game controllers
// ...such as my Xbox 360 controller.
//
// This is a quick mash-up using Lager's Gcp_gamepad animated eyes example code,
// (which is in the GCP library: In Processing, go to File > Examples..., then Contributed Libraries > Game Control Plus)
// and Rebecca Fiebrink's Simple_Mouse_DraggedObject_2Inputs example code for Wekinator.
@drscotthawley
drscotthawley / WebAudioFreqGain.html
Last active Mar 13, 2018
WebAudio OSC Output for use with Wekinator
View WebAudioFreqGain.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>WebAudio OSC Output Example - 2 Variables</title>
<!-- By Scott Hawley @drscotthawley. Modified from https://github.com/automata/osc-web/blob/master/web-side/app.html
No additional license restrictions are introduced with these modifications; the automata/osc-web site gives no license info.
Thus as far as this author is concerned: "unlimited license": feel free to use & modify in any way you wish! -->
</head>
<body>
<h2>WebAudio OSC Output Example - 2 Variables</h2>
@drscotthawley
drscotthawley / faves2bibtex.py
Last active Jan 19, 2018
Utility to generate BibTex from list of Tweets you (or another user) have favorited ('liked'), tweeted or RT'd
View faves2bibtex.py
#! /usr/bin/env python3
"""
faves2bibtex.py
Author: Scott Hawley
Scrapes URLs contained in tweets you (or another user) favorited ('liked') for DOI & other bibliographic info,
and tries to generate a set of BibTex entries to stdout.
Status messages go to stderr
Sample usage:
You can’t perform that action at this time.