Skip to content

Instantly share code, notes, and snippets.

@zhreshold
zhreshold / mobilenet.py
Last active May 23, 2017 20:23
MobileNet 224x224
"""References:
Andrew G. Howard, Menglong Zhu, Bo Chen, Dmitry Kalenichenko, Weijun Wang,
Tobias Weyand, Marco Andreetto, Hartwig Adam.
"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications."
arXiv preprint arXiv:1704.04861
"""
import mxnet as mx
def depthwise_conv(data, kernel, pad, num_filter, num_group, stride, name):
conv = mx.symbol.Convolution(data=data, kernel=kernel, pad=pad, stride=stride,
@zhreshold
zhreshold / inflated.py
Last active June 23, 2017 17:15
inflated network
import mxnet as mx
def inflated_layer(data, num_in, num_out, name):
assert(num_out % num_in == 0)
num_group = num_out / num_in
outputs = []
for i in range(num_group):
bias = mx.sym.Variable(shape=(1, num_in, 1, 1),
name="{}_{}_bias".format(name, i))
outputs.append(mx.sym.broadcast_add(lhs=data, rhs=bias))
@zhreshold
zhreshold / vgg_depthwise.py
Created April 26, 2017 19:54
Benchmark simulation for vgg with depth-wise convolution
"""References:
Simonyan, Karen, and Andrew Zisserman. "Very deep convolutional networks for
large-scale image recognition." arXiv preprint arXiv:1409.1556 (2014).
"""
import mxnet as mx
def depthwise_conv(data, kernel, pad, num_filter, name, num_group):
conv = mx.symbol.Convolution(data=data, kernel=kernel, pad=pad,
num_filter=num_group, name=name+'_depthwise', num_group=num_group)
@zhreshold
zhreshold / create_toy_pascal.py
Created July 21, 2017 22:15
Create toy pascal dataset
import numpy as np
OLD_CLASSES = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car',
'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike',
'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
NEW_CLASSES = ['bicycle', 'bus', 'car', 'cat', 'cow', 'dog', 'horse', 'motorbike',
'person', 'train']
OLD_INDICES = [OLD_CLASSES.index(x) for x in NEW_CLASSES]
@zhreshold
zhreshold / Convolutional_structures.md
Created July 26, 2017 20:36
Convolutional structure tricks and techniques

Techniques to accelerate convolutional neural networks

  • Depthwise convolution (mobilenet)
  • Shufflenet
  • Densenet
@zhreshold
zhreshold / test_image_iter.py
Last active August 22, 2017 22:25
Test mxnet image iter performance
import mxnet as mx
print(mx.__version__)
import time
import os
print('worker:', os.environ.get('MXNET_CPU_WORKER_NTHREADS', 1))
num_batch = 100
batch_size = 32
data_shape = (3, 224, 224)
@zhreshold
zhreshold / googlenet.prototxt
Created September 15, 2017 00:25
Googlenet deploy
name: "GoogleNet"
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 10 dim: 3 dim: 224 dim: 224 } }
}
layer {
name: "conv1/7x7_s2"
type: "Convolution"
@zhreshold
zhreshold / fc_bench.py
Last active October 5, 2017 18:48
FC perf benchmark
import mxnet as mx
import numpy as np
from timeit import default_timer as timer
def get_bench_net(num_hidden=10000):
data = mx.sym.var('data')
fc = mx.sym.FullyConnected(data, num_hidden=num_hidden)
return fc
num_out = 10000
@zhreshold
zhreshold / resnet101_v2.sh
Last active October 12, 2017 23:31
MXNet Imagenet training configurations
python train_imagenet.py --data-train ~/data/train.rec --data-val ~/data/val.rec --gpus 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 --data-nthreads 32 --network resnet101_v2 --batch-size 256 --top-k 5 --model-prefix model/resnet101_v2 --min-random-scale 0.533 --max-random-shear-ratio 0 --max-random-rotate-angle 0 --max-random-h 0 --max-random-l 0 --max-random-s 0 --lr-step-epochs 30,60,90 --num-epochs 120 --rgb-std '58.395,57.12,57.375'
@zhreshold
zhreshold / bullet.js
Last active October 14, 2017 03:44
d3.js demo
(function() {
// Chart design based on the recommendations of Stephen Few. Implementation
// based on the work of Clint Ivy, Jamie Love, and Jason Davies.
// http://projects.instantcognition.com/protovis/bulletchart/
d3.bullet = function() {
var orient = "left", // TODO top & bottom
reverse = false,
duration = 0,
ranges = bulletRanges,