Code Monkey home page Code Monkey logo

pytorch_quantization's Introduction

Dorefa-net

A pytorch implementation of dorefa.The code is inspired by LaVieEnRoseSMZ and zzzxxxttt.

Requirements

  • python > 3.5
  • torch >= 1.1.0
  • torchvision >= 0.4.0
  • tb-nightly, future (for tensorboard)
  • nvidia-dali >= 0.12 (faster dataloader)

Cifar-10 Accuracy

Quantized model are trained from scratch

Model W_bit A_bit Acc
resnet-18 32 32 94.71%
resnet-18 4 4 94.36%
resnet-18 1 4 93.87%

ImageNet Accuracy

Quantized model are trained from scratch

Model W_bit A_bit Top1 Top5
resnet-18 32 32 69.80% 89.32%
resnet-18 4 4 66.60% 87.15%

Usages

Download the ImageNet dataset and move validation images to labeled subfolders.To do this, you can use the following script

  • To train the model
python3 cifar_train_eval.py    
python3 imagenet_torch_loader --multiprocessing-distributed    or    python3 imagenet_dali_loader.py 
  • To check the tensorboard log

     tensorboard --logdir='your_log_dir'
    

    then navigating to https://localhost:6006 .

  • To test the quantized model and bn fused

    • convert to the quantized model for inference
     python3 test_fused_quant_model.py
    
    • test bn fuse on the float model
     python3 bn_fuse.py
    

    Obviously, this fusion method is not suitable for quantized models. We will change the bn fuse in the future according to the paper section 3.2.2.

    This bn fuse test result is not serious. However, it is OK to explain the problem qualitatively.

Model on CPU before fuse after fuse
resnet-18 0.74 s 0.51 s
resnet-34 1.41 s 0.92 s
resnet-50 1.96 s 1.02 s

To do

  • Train on imagenet2012
  • Fold bn
  • Test speedup from quantization and bn fold
  • Deploy models to embedded devices
  • ...

pytorch_quantization's People

Contributors

jzz24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pytorch_quantization's Issues

关于量化精度的请教

大佬你好,请问做8bit量化的时候,转成量化模型quant_model的时候,为什么权值是小数吖,比如是0.4256之类的,为什不是0-255之间的整数呢?还是说我哪儿操作步骤有问题
恳请大佬教做人,刚入门量化的小白,感激不尽!

yolov5的4bit量化

请问这个算法对于yolov5s做4bit量化有效果吗,如果有的话,训练epoch大概需要多少,还有可以使用什么方法加快训练呢

Not same with the Paper

activation quantization is not same

In the paper :
x(real) is in range[0 ~ 1] : clamp(input, 0, 1)
then, quantize(x)

In your implementation:
clamp(input * 0.1, 0, 1)

ResNet50 在ImageNet数据集

你好,我想问一下,ResNet18在位宽为4时top5精度已经下降了接近了2%了。那将数据位宽提高到6,或者8效果如何呢。谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.