Home

Awesome

This is a playground for pytorch beginners, which contains predefined models on popular dataset. Currently we support

Here is an example for MNIST dataset. This will download the dataset and pre-trained model automatically.

import torch
from torch.autograd import Variable
from utee import selector
model_raw, ds_fetcher, is_imagenet = selector.select('mnist')
ds_val = ds_fetcher(batch_size=10, train=False, val=True)
for idx, (data, target) in enumerate(ds_val):
    data =  Variable(torch.FloatTensor(data)).cuda()
    output = model_raw(data)

Also, if want to train the MLP model on mnist, simply run python mnist/train.py

Install

python3 setup.py develop --user

ImageNet dataset

We provide precomputed imagenet validation dataset with 224x224x3 size. We first resize the shorter size of image to 256, then we crop 224x224 image in the center. Then we encode the cropped images to jpg string and dump to pickle.

Quantization

We also provide a simple demo to quantize these models to specified bit-width with several methods, including linear method, minmax method and non-linear method.

quantize --type cifar10 --quant_method linear --param_bits 8 --fwd_bits 8 --bn_bits 8 --ngpu 1

Top1 Accuracy

We evaluate the performance of popular dataset and models with linear quantized method. The bit-width of running mean and running variance in BN are 10 bits for all results. (except for 32-float)

Model32-float12-bit10-bit8-bit6-bit
MNIST98.4298.4398.4498.4498.32
SVHN96.0396.0396.0496.0295.46
CIFAR1093.7893.7993.8093.5890.86
CIFAR10074.2774.2174.1973.7066.32
STL1077.5977.6577.7077.5973.40
AlexNet55.70/78.4255.66/78.4155.54/78.3954.17/77.2918.19/36.25
VGG1670.44/89.4370.45/89.4370.44/89.3369.99/89.1753.33/76.32
VGG1971.36/89.9471.35/89.9371.34/89.8870.88/89.6256.00/78.62
ResNet1868.63/88.3168.62/88.3368.49/88.2566.80/87.2019.14/36.49
ResNet3472.50/90.8672.46/90.8272.45/90.8571.47/90.0032.25/55.71
ResNet5074.98/92.1774.94/92.1274.91/92.0972.54/90.442.43/5.36
ResNet10176.69/93.3076.66/93.2576.22/92.9065.69/79.541.41/1.18
ResNet15277.55/93.5977.51/93.6277.40/93.5474.95/92.469.29/16.75
SqueezeNetV056.73/79.3956.75/79.4056.70/79.2753.93/77.0414.21/29.74
SqueezeNetV156.52/79.1356.52/79.1556.24/79.0354.56/77.3317.10/32.46
InceptionV376.41/92.7876.43/92.7176.44/92.7373.67/91.341.50/4.82

Note: ImageNet 32-float models are directly from torchvision

Selected Arguments

Here we give an overview of selected arguments of quantize.py

FlagDefault valueDescription & Options
typecifar10mnist,svhn,cifar10,cifar100,stl10,alexnet,vgg16,vgg16_bn,vgg19,vgg19_bn,resent18,resent34,resnet50,resnet101,resnet152,squeezenet_v0,squeezenet_v1,inception_v3
quant_methodlinearquantization method:linear,minmax,log,tanh
param_bits8bit-width of weights and bias
fwd_bits8bit-width of activation
bn_bits32bit-width of running mean and running vairance
overflow_rate0.0overflow rate threshold for linear quantization method
n_samples20number of samples to make statistics for activation