Skip to content

Instantly share code, notes, and snippets.

try:
range = xrange # Python 2
except NameError:
pass # Python 3
def lazy_product(*iter_funcs, **kwargs):
"""
If f1, f2, ..., are functions which have no (required) arguments and
return iterables, then
lazy_product(f1, f2, ..., repeat=k)
@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
#!/usr/local/bin/python3
import itertools
import string
class Node:
"""A trie node."""
def __init__(self, char, parent=None):
self._char = char
@jeffdonahue
jeffdonahue / bvlc_reference_alexnet_train_log.txt
Last active December 9, 2017 10:11
Training log for the BVLC AlexNet reference model.
This file has been truncated, but you can view the full file.
I1224 11:43:56.783612 2133 train_net.cpp:26] Starting Optimization
I1224 11:43:56.783983 2133 solver.cpp:26] Creating training net.
I1224 11:43:56.784008 2133 net.cpp:66] Creating Layer data
I1224 11:43:56.784013 2133 net.cpp:101] data -> data
I1224 11:43:56.784023 2133 net.cpp:101] data -> label
I1224 11:43:56.784036 2133 data_layer.cpp:122] Opening leveldb /home/jdonahue/caffe-train-leveldb
I1224 11:43:56.956717 2133 data_layer.cpp:159] output data size: 256,3,227,227
I1224 11:43:56.956765 2133 data_layer.cpp:176] Loading mean file from/home/jiayq/ilsvrc2012_mean.binaryproto
I1224 11:43:57.016316 2133 net.cpp:116] Top shape: 3 227 227
I1224 11:43:57.016341 2133 net.cpp:116] Top shape: 1 1 1
@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}