GithubHelp home page GithubHelp logo

model_compression's Introduction

model_compression

Implementation of model compression with three knowledge distilling or teacher student methods [1][2][3].
The basic architecture is teacher-student model.

cifar-10

I used cifar-10 dataset to do this work.

Download cifar-10 dataset

wget https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz

Implementation

In this the work, I use network in network[5] as teacher model, lenet[6] as student model.
The teacher model is pre-trained by caffe. And extract the model weight by [4].
Both network-in-network and lenet have little different from original model.
In docs, there are two images for the network architecture.

"teacher.npy" is the pre-trained model weights of teacher model.

"student.npy" is the model weights train on lenet, using ground turth label directly.

#Usage In teacher-student.py, there is three methods to train student network.
You need to modify the cifar-dataset-path in function read_cifar10

###Basic Usage train by [1]

python teacher-student.py --task train --model savemodel

train by [2]

python teacher-student.py --task train --model savemodel --noisy [--noisy_ratio --noisy_sigma]

train by [3]

python teacher-student.py --task train --model savemodel --KD [--lamda --tau]


**testing** >python teacher-student.py --task test --model trained_model
**validation** Also, you can validate your pre-trained teacher model by
> python teacher-student.py --task val

This can make sure that your caffe-teacher-model transfer to tensorflow successfully.
python teacher-student.py -h for more information

Result

All three methods train 100 epochs, with dropout ratio=0.8, lr=1e-3, decay 0.1 at 80th epoch.
In method[2], noisy_ratio=0.5, sigma=0.1.
In methos[3], lamda=0.3, tau=0.3.

This table shows the accuracy on testing dataset, test by 100-epoch-model.
See more details in result.

method[1] method[2] method[3]
71.97% 70.63% 70.96%

The accuarcy of original model which directly learn by ground truth label:
teacher model : 78.1%
student model : 66.15%

References

[1] Ba, J. and Caruana, R. Do deep nets really need to be deep? In NIPS 2014.

[2] Bharat Bhusan Sau Vineeth N. Balasubramanian, Deep Model Compression: Distilling Knowledge from Noisy Teachers. arXiv 2016.

[3] Hinton, G. E., Vinyals, O., and Dean, J. Distilling the knowledge in a neural network. arXiv 2015.

[4] https://github.com/ethereon/caffe-tensorflow

[5] Network in Network model - https://github.com/aymericdamien/TensorFlow-Examples/

[6] Y. LeCun, L. Bottou, Y. Bengio and P. Haffner: Gradient-Based Learning Applied to Document Recognition, Proceedings of the IEEE 1998

model_compression's People

Contributors

chengshengchan 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

model_compression's Issues

Teacher model performance

Hi. Thanks for sharing your code. I am wondering why your teacher's model (NIN) has 78% accuracy, which is lower than the one reported in the paper.

迭代100次后loss不在发生变化

你好。我在使用您的代码,用imagenet训练数据集,训练resnet(teacher) / queezenet(student)网络。
但是不管lr设置成0.1还是0.001,(batch_size)都是迭代140次左右loss稳定在一个值,并且不同的lr稳定的loss值都相同。 以您的经验能否指导下出现这种问题的可能原因?

there have a problem when i run the code

hi , when run the code ,as follow:

python teacher-student.py --task test --model trained_model
i want to know what is the folder of trained_model, and i change the code :
python teacher-student.py --task test --model trained_model to >python teacher-student.py --task test --model savemodel, but didn't make it.

Wrong lose function in Hinton method

Here instead of teacher_tau I think it should be y (placeholder variable). Because we want to give this value as input to the loss function. And in order to give input we have to use placeholder variable, isn't it.

使用KD训练student network的问题

想请问,在训练过程中,代码里面是如何保证只更新student network的权重的?
另外,在训练过程中,数据集的label应该是没有用到吧?

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.