All Projects → Irtza → Keras_model_compression

Irtza / Keras_model_compression

Model Compression Based on Geoffery Hinton's Logit Regression Method in Keras applied to MNIST 16x compression over 0.95 percent accuracy.An Implementation of "Distilling the Knowledge in a Neural Network - Geoffery Hinton et. al"

Projects that are alternatives of or similar to Keras model compression

Dl Workshop Series
Material used for Deep Learning related workshops for Machine Learning Tokyo (MLT)
Stars: ✭ 857 (+1352.54%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Keras Faster Rcnn
Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
Stars: ✭ 28 (-52.54%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Traffic Sign Classifier
Udacity Self-Driving Car Engineer Nanodegree. Project: Build a Traffic Sign Recognition Classifier
Stars: ✭ 12 (-79.66%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
All Classifiers 2019
A collection of computer vision projects for Acute Lymphoblastic Leukemia classification/early detection.
Stars: ✭ 22 (-62.71%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Svhn Cnn
Google Street View House Number(SVHN) Dataset, and classifying them through CNN
Stars: ✭ 44 (-25.42%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Plaquebox Paper
Repo for Tang et al, bioRxiv 454793 (2018)
Stars: ✭ 23 (-61.02%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Deep learning projects
Stars: ✭ 28 (-52.54%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Build Ocr
Build an OCR for iOS apps
Stars: ✭ 17 (-71.19%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Computervision Recipes
Best Practices, code samples, and documentation for Computer Vision.
Stars: ✭ 8,214 (+13822.03%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Yann
This toolbox is support material for the book on CNN (http://www.convolution.network).
Stars: ✭ 41 (-30.51%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Fssgi
Exploratory Project on Fast Screen Space Global Illumination
Stars: ✭ 22 (-62.71%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Very Deep Convolutional Networks For Natural Language Processing In Tensorflow
implement the paper" Very Deep Convolutional Networks for Natural Language Processing"(https://arxiv.org/abs/1606.01781 ) in tensorflow
Stars: ✭ 54 (-8.47%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Deep Visual Attention Prediction
Keras implementation of paper 'Deep Visual Attention Prediction' which predicts human eye fixation on view-free scenes.
Stars: ✭ 19 (-67.8%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Twitter sentiment analysis word2vec convnet
Twitter Sentiment Analysis with Gensim Word2Vec and Keras Convolutional Network
Stars: ✭ 24 (-59.32%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Cat Dog Cnn Classifier
This classifier use Convolution Neural Network approch for kaggle problem to classify Cat vs Dog images.
Stars: ✭ 19 (-67.8%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Brain Tumor Segmentation Keras
Keras implementation of the multi-channel cascaded architecture introduced in the paper "Brain Tumor Segmentation with Deep Neural Networks"
Stars: ✭ 20 (-66.1%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Caffenet Benchmark
Evaluation of the CNN design choices performance on ImageNet-2012.
Stars: ✭ 700 (+1086.44%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Skin Cancer Image Classification
Skin cancer classification using Inceptionv3
Stars: ✭ 16 (-72.88%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Teacher Student Training
This repository stores the files used for my summer internship's work on "teacher-student learning", an experimental method for training deep neural networks using a trained teacher model.
Stars: ✭ 34 (-42.37%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks
Accurate Binary Convolution Network
Binary Convolution Network for faster real-time processing in ASICs
Stars: ✭ 49 (-16.95%)
Mutual labels:  jupyter-notebook, convolutional-neural-networks

Keras Model Compression

An Implementation of "Distilling the Knowledge in a Neural Network - Geoffery Hinton et. al" https://arxiv.org/abs/1503.02531

Usage

python runme.py

Initial Model Parameters:
  • Total params: 1,199,882
  • Trainable params: 1,199,882

Model Evaluation before compression

  • Initial Accuracy on test set~= 0.99
  • Initial Model Parameters : 1199882
  • Memory footprint per Image Feed Forward ~= ', 4.577 Mb
Evaluation of the Model after compression
  • Compressed Model parameters: 74188
  • Compression Rate : 16.2x
  • Accuracy : 0.96

Implementation of Logit Regression in Keras

Experiments and thoughts to investigate the affect of number of parameters in Model.

Convolutional Network Model Architecture and Summary


Layer (type) Output Shape Param # Connected to
convolution2d_1 (Convolution2D) (None, 26, 26, 32) 320 convolution2d_input_1[0][0]
convolution2d_2 (Convolution2D) (None, 24, 24, 64) 18496 convolution2d_1[0][0]
maxpooling2d_1 (MaxPooling2D) (None, 12, 12, 64) 0 convolution2d_2[0][0]
dropout_1 (Dropout) (None, 12, 12, 64) 0 maxpooling2d_1[0][0]
flatten_1 (Flatten) (None, 9216) 0 dropout_1[0][0]
dense_1 (Dense) (None, 128) 1179776 flatten_1[0][0]
dropout_2 (Dropout) (None, 128) 0 dense_1[0][0]
dense_2 (Dense) (None, 10) 1290 dropout_2[0][0]
activation_1 (Activation) (None, 10) 0 dense_2[0][0]

  • Total params: 1,199,882
  • Trainable params: 1,199,882
  • Non-trainable params: 0

Reducing The Model

If we observe the model weights and number of parameters, the most consuming layers are the 2 Dense Layers. and the two convolutuonal layers have only 18,816 parameters. Accounting for only (18816 / 1,199,882) x 100 = 1.56 percent of all the parameters,

So the first Step is to either to replace it with a lighter model. That generalizes well to new examples, and learns to model the heavy dense layer of the original model.

Replacing these 2 heavy dense layers with 1 Hidden layer with 6 HiddenLayer Neurons. We can achieve an accuracy of 0.9626.

The Logits from the last layer. before the Activation layer were used, as mentioned in Geoffery Hinton's paper to avoid encoutering very small activation values after squashing through Softmax function.

The python Notebook in this repository shows other architectures with varying number of hiddenLayer Neurons, and the affect of HiddenNeurons on the accuracy. See plots/ subdirectory for findings

Evaluation of the Model after Reduction

  • Compressed Model parameters: 74188
  • Compression Rate : 16.2x

Exepriments on how we can trade accuracy with model size. initial model accuracy is 99%. The minimum model size that we can achieve without dropping below 0.95 accuracy.

Experiment: THe number of hidden Layer Neurons in small model was iteratively decreased, this showed a exponential decrease in model size and linear decrease in accuracy.

By examining the plot of number of parameters(or model size) to accuracy. we can find the tradeoff, in the number of Hidden Layer Neurons needed to achieve atleast 0.95 accuracy.

I was able to obtain 16.2x times compression, while keeping accuracy at 0.96

Compression-Rate-Accuracy{:class="img-responsive"} ParameterSize-Accuracy{:class="img-responsive"}

Experiment Settings and Hyper Parameters for student model.

Various Dropouts were tested . 0.2 was chosen to regularize a bit, and showed good generalization accuracy.

lossFunction : Mean Square Error as mentioned by Geoff Hinton in the paper.. Optimized Adadelta optimizer over

Let s(f) be the minimum model size that can achieve accuracy f. Given 0 <= f_1 < f_2 < ... < f_n < =1, 0 < s(f_1) < s(f_2) < ... < s(f_n)

No, The above equation representing the relation of model size and minimum accuray does not hold. During my experiments I have found that accuracy has rised/equal even when the model size was reduced several x times .

However, after plotting the accuracy against model size. it is observed that the accuracy decreases as model size is reduced.

Future Work and Improvements :

Its also worth noting that in MNIST dataset the characters only appear in the center of the image, and convolution weights corresponding to the edges are blank/constant and likely to be highly redundant or noisy. Pruning these weight connections through the network is likely to effectively reduce model size.

Ideas from Song Hans work in deep compression can be taken forward to establish a general framework for compression of deep-learning models in keras.

See Hans work here: https://arxiv.org/abs/1510.00149 "Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman Coding"

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].