Skip to content

Instantly share code, notes, and snippets.

#!/usr/local/bin/python3
import itertools
import string
class Node:
"""A trie node."""
def __init__(self, char, parent=None):
self._char = char
@jeffdonahue
jeffdonahue / .slate
Created July 17, 2017 13:44 — forked from teruhisa/.slate
slate sizeup settings
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
# Resize Bindings
# bind right:alt resize +10% +0
# bind left:alt resize -10% +0
# bind up:alt resize +0 -10%
# bind down:alt resize +0 +10%
# bind right:ctrl;alt resize -10% +0 bottom-right
import numpy as np
import theano
import theano.tensor as T
low = 'float32'
high = 'float64'
dtype_low, dtype_high = [T.TensorType(f, (False,)) for f in [low, high]]
pred32, target32 = dtype_low('p'), dtype_low('t')
pred64, target64 = dtype_high('p'), dtype_high('t')
import numpy as np
import theano
import theano.tensor as T
pred, target = T.vectors('pt') # pred in (-inf, +inf), target in [0, 1]
L1 = T.nnet.binary_crossentropy(T.nnet.sigmoid(pred), target).sum()
L2 = T.nnet.sigmoid_binary_crossentropy(pred, target).sum()
fl1, fl2 = [theano.function([pred, target], L) for L in (L1, L2)]
g1, g2 = [theano.grad(L, [pred, target]) for L in (L1, L2)]
#!/usr/bin/env python
import numpy as np
def convert(image):
image = np.asarray(image)
if len(image.shape) == 2:
image = image[..., np.newaxis]
assert len(image.shape) == 3
return image.transpose(2, 0, 1).copy()
net: "train_val.prototxt"
test_iter: 736
test_interval: 1000000 # py solving tests
display: 1
average_loss: 100
# lr_policy: "fixed"
lr_policy: "step"
stepsize: 50000
gamma: 0.1
# base_lr: 1e-4
#!/bin/bash
set -x
set -e
export LD_LIBRARY_PATH='/usr/local/cuda/lib64/'
export PYTHONUNBUFFERED="True"
NAME="scratch"
NAME="/tmp/magic_caffenet.caffenet"
if [ "$#" -ge 1 ]; then
NAME=${2}
#!/usr/bin/env bash
set -e
set -x
GPU=0
CWD=$(pwd)
CAFFE_DIR=/raid/jdonahue/philkr-caffe
MAGIC_DIR=~/magic_init
CLASS_DIR=/raid/jdonahue/voc-classification
import numpy as np
def canonical_axis(x, axis):
def is_int_ndarray(x):
if not isinstance(x, np.ndarray):
return False
dtype = str(x.dtype)
prefixes = 'int', 'uint'
return any(dtype.startswith(p) for p in prefixes)
if axis is None:
@jeffdonahue
jeffdonahue / resize_imageset.py
Last active April 9, 2020 16:38
resize a directory of images
#!/usr/bin/env python
from __future__ import division
import functools
import itertools
import numpy as np
import os
import matplotlib.pyplot as plt
from PIL import Image