Skip to content

Instantly share code, notes, and snippets.

@keunwoochoi
keunwoochoi / spectrogram_scrolling_video.sh
Created July 18, 2019 23:09
Generate a video with scrolling over the spectrogram of the input audio.
# This is a simplified script of https://gist.github.com/keunwoochoi/f0ea2c49355fc21e93dad88d210efcdd
# Usage: 1. Modify the font path in the line with [ss].
# In my case, I copied and pasted CircularSpAraTTBlack.ttf to the same folder.
# 2. Put the wav file in the same folder, say, audio_file.wav
# 3. run $./spectrogram_scrolling_video.sh audio_file.wav
# 4. You'll see audio_file.mkv in the same folder!
#
# Based on example here https://trac.ffmpeg.org/wiki/Encode/YouTube
text=$(basename $1 .wav)
ffmpeg -i $1 -filter_complex \
@munificent
munificent / generate.c
Last active March 18, 2024 08:31
A random dungeon generator that fits on a business card
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#define r return // 2008-2019
#define l(a, b, c, d) for (i y=a;y\
<b; y++) for (int x = c; x < d; x++)
typedef int i;const i H=40;const i W
=80;i m[40][80];i g(i x){r rand()%x;
}void cave(i s){i w=g(10)+5;i h=g(6)
+3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
@willwhitney
willwhitney / handle_slurm_signals.py
Created August 24, 2018 19:56
Fragment of python code for catching signals from Slurm and restarting the job
import signal
# depends on requesting SIGUSR1 in runner file: https://gist.github.com/willwhitney/e1509c86522896c6930d2fe9ea49a522
def handle_signal(signal_value, _):
signame = signal.Signals(signal_value).name
if signal_value == signal.SIGUSR1:
print('Process {} got signal {}. Saving and restarting.'.format(
os.getpid(), signame), flush=True)
save_dynamics(epoch)
@carlthome
carlthome / Signal reconstruction from spectrograms.ipynb
Created May 31, 2018 13:53
Try to recover audio from filtered magnitudes when phase information has been lost.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jessfraz
jessfraz / boxstarter.ps1
Last active April 11, 2024 16:02
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Jess Frazelle <jess@linux.com>
# Last Updated: 2017-09-11
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt:
@brainstorm
brainstorm / fix_osx_pcbnew_kicad_libs.sh
Created September 1, 2017 16:24
Fix KiCAD's pcbnew python scripting support for OSX
#!/bin/bash
# Inspired on: https://www.bountysource.com/issues/31269729-libwx_osx_cocoau-3-1-dylib-not-found
KICAD_LIBS_TOFIX="libwx_osx_cocoau_gl-3.0.0 libwx_osx_cocoau_adv-3.0.0 libwx_osx_cocoau_aui-3.0.0 libwx_osx_cocoau_adv-3.0.0 libwx_osx_cocoau_html-3.0.0 libwx_osx_cocoau_core-3.0.0 libwx_osx_cocoau_stc-3.0.0 libkicad_3dsg.2.0.0 libGLEW.2.0.0 libcairo.2 libpixman-1.0 libwx_baseu_net-3.0.0 libwx_baseu-3.0.0 libwx_baseu_xml-3.0.0"
#KICAD_LIBS_TOFIX=`find /Applications/Kicad/kicad.app/Contents/Frameworks/ -iname *.dylib | xargs otool -L | grep executable_path | awk '{print $1}' | awk -F'/' '{print $4}'`
for kicadlib in $KICAD_LIBS_TOFIX;
do
echo "Fixing ${kicadlib} broken path on pcbnew..."
from graphviz import Digraph
import torch
from torch.autograd import Variable, Function
def iter_graph(root, callback):
queue = [root]
seen = set()
while queue:
fn = queue.pop()
if fn in seen:
# Inception Score Calculator
#
# A Brock, 2017
#
# This snippet assumes you have two functions defined:
# 1. sample_net, which takes in a batch x num_latents random vector and returns batch samples,
# 2. eval_net, which takes in batch samples and returns a batch x #classes prediction vector.
num_latents = 100

A Tour of PyTorch Internals (Part I)

The fundamental unit in PyTorch is the Tensor. This post will serve as an overview for how we implement Tensors in PyTorch, such that the user can interact with it from the Python shell. In particular, we want to answer four main questions:

  1. How does PyTorch extend the Python interpreter to define a Tensor type that can be manipulated from Python code?
  2. How does PyTorch wrap the C libraries that actually define the Tensor's properties and methods?
  3. How does PyTorch cwrap work to generate code for Tensor methods?
  4. How does PyTorch's build system take all of these components to compile and generate a workable application?

Extending the Python Interpreter

PyTorch defines a new package torch. In this post we will consider the ._C module. This module is known as an "extension module" - a Python module written in C. Such modules allow us to define new built-in object types (e.g. the Tensor) and to call C/C++ functions.

@kastnerkyle
kastnerkyle / extract_feats.py
Last active December 12, 2022 21:27
Extract features with HTK/speech_tools/festival/merlin
from __future__ import print_function
import os
import shutil
import stat
import subprocess
import time
import numpy as np
from scipy.io import wavfile
import re
import glob