Skip to content

Instantly share code, notes, and snippets.

import logging
import pyparsing as pp
pp.ParserElement.enablePackrat()
logging.basicConfig(format='%(message)s', level=logging.DEBUG)
LOG = logging.getLogger()
def unwrap(toks):
if len(toks) == 1:
@crowsonkb
crowsonkb / site.cfg
Created March 5, 2016 21:58
numpy site.cfg for mkl on os x 10.11
# This file provides configuration information about non-Python dependencies for
# numpy.distutils-using packages. Create a file like this called "site.cfg" next
# to your package's setup.py file and fill in the appropriate sections. Not all
# packages will use all sections so you should leave out sections that your
# package does not use.
# To assist automatic installation like easy_install, the user's home directory
# will also be checked for the file ~/.numpy-site.cfg .
# The format of the file is that of the standard library's ConfigParser module.
@crowsonkb
crowsonkb / gfortran
Created March 5, 2016 23:57
A horrible wrapper command for gfortran, needed to build scipy against MKL
#!/usr/bin/env python
import os
import sys
FC = '/usr/local/bin/gfortran'
newargs = []
eat_next_arg = False
for arg in sys.argv[1:]:
@crowsonkb
crowsonkb / ResNet_50_1by2_nsfw.prototxt
Created October 15, 2016 11:04
ResNet_50_1by2_nsfw prototxt modified for style_transfer
name: "ResNet_50_1by2_nsfw"
force_backward: true
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 1 dim: 3 dim: 224 dim: 224 } }
}
layer {
name: "conv_1"
@crowsonkb
crowsonkb / denoise.py
Last active March 15, 2022 14:16
Total variation denoising
#!/usr/bin/env python3
"""Total variation denoising."""
import argparse
import time
import numpy as np
from PIL import Image
from scipy.linalg import blas
--[[ An experimental quasi-Newton optimizer.
Incorporates Hessian damping, momentum, and per-feature learning rate scaling.
Also implements optional polynomial-decay averaging (similar to ASGD).
ARGS:
- 'opfunc' : a function that takes a single input (X), the point
of a evaluation, and returns f(X) and df/dX
- 'x' : the initial point
- 'config` : a table with configuration parameters for the optimizer
@crowsonkb
crowsonkb / dmsqn.py
Last active February 26, 2017 03:56
Experimental quasi-Newton optimizer for image synthesis from CNNs
import numpy as np
from scipy.linalg import blas
from scipy.ndimage import zoom
# Machine epsilon for float32
EPS = np.finfo(np.float32).eps
# pylint: disable=no-member
def dot(x, y):
name: "VGG_ILSVRC_16_layers_conv"
force_backward: true
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 1 dim: 3 dim: 224 dim: 224 } }
}
layer {
bottom: "data"
import argparse
from functools import partial, reduce
import math
from pathlib import Path
import random
from keras.layers import *
from keras.models import Model
from keras.utils import io_utils
@crowsonkb
crowsonkb / hsl.py
Created May 11, 2018 20:29
Converts colors from HSL to RGB and back.
"""Converts colors from HSL to RGB and back."""
import numpy as np
from scipy import optimize
def tstack(a):
"""Stacks arrays in sequence along the last axis (tail)."""
a = np.asarray(a)
return np.concatenate([x[..., np.newaxis] for x in a], axis=-1)