Skip to content

Instantly share code, notes, and snippets.

@zhreshold
zhreshold / symbol_darknet19.py
Last active November 3, 2017 04:23
darknet 19 224x224
"""
Reference:
J. Redmon. Darknet: Open source neural networks in c.
http://pjreddie.com/darknet/, 2013-2016. 5
"""
import mxnet as mx
def conv_act_layer(from_layer, name, num_filter, kernel=(3, 3), pad=(1, 1), \
stride=(1,1), act_type="relu", use_batchnorm=True):
@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 / 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 / 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 / train_imagenet.py
Last active April 28, 2018 04:19
Train imagenet using gluon
import argparse, time
import logging
logging.basicConfig(level=logging.INFO)
fh = logging.FileHandler('training.log')
logger = logging.getLogger()
logger.addHandler(fh)
import mxnet as mx
from mxnet import gluon
from mxnet.gluon import nn
@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 / check_platform.py
Last active May 30, 2019 14:39
Check OS/Python/Cpu Info and Network connections
"""Diagnose script for checking OS/hardware/python/pip/mxnet/network.
The output of this script can be a very good hint to issue/problem.
"""
import platform, subprocess, sys, os
import socket, time
try:
from urllib.request import urlopen
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
@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"