All Projects → BenWhetton → Keras Surgeon

BenWhetton / Keras Surgeon

Licence: other
Pruning and other network surgery for trained Keras models.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Keras Surgeon

jetbrains-utility
Remove/Backup – settings & cli for macOS (OS X) – DataGrip, AppCode, CLion, Gogland, IntelliJ, PhpStorm, PyCharm, Rider, RubyMine, WebStorm
Stars: ✭ 62 (-81.71%)
Mutual labels:  pruning
nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (-79.65%)
Mutual labels:  pruning
SIGIR2021 Conure
One Person, One Model, One World: Learning Continual User Representation without Forgetting
Stars: ✭ 23 (-93.22%)
Mutual labels:  pruning
Generalizing-Lottery-Tickets
This repository contains code to replicate the experiments given in NeurIPS 2019 paper "One ticket to win them all: generalizing lottery ticket initializations across datasets and optimizers"
Stars: ✭ 48 (-85.84%)
Mutual labels:  pruning
Deep-Compression.Pytorch
Unofficial Pytorch implementation of Deep Compression in CIFAR10
Stars: ✭ 29 (-91.45%)
Mutual labels:  pruning
RMNet
RM Operation can equivalently convert ResNet to VGG, which is better for pruning; and can help RepVGG perform better when the depth is large.
Stars: ✭ 129 (-61.95%)
Mutual labels:  pruning
Pruning filters for efficient convnets
PyTorch implementation of "Pruning Filters For Efficient ConvNets"
Stars: ✭ 96 (-71.68%)
Mutual labels:  pruning
Yolov3 Network Slimming
yolov3 network slimming剪枝的一种实现
Stars: ✭ 320 (-5.6%)
Mutual labels:  pruning
jp-ocr-prunned-cnn
Attempting feature map prunning on a CNN trained for Japanese OCR
Stars: ✭ 15 (-95.58%)
Mutual labels:  pruning
TextPruner
A PyTorch-based model pruning toolkit for pre-trained language models
Stars: ✭ 94 (-72.27%)
Mutual labels:  pruning
batchnorm-pruning
Rethinking the Smaller-Norm-Less-Informative Assumption in Channel Pruning of Convolution Layers https://arxiv.org/abs/1802.00124
Stars: ✭ 66 (-80.53%)
Mutual labels:  pruning
Regularization-Pruning
[ICLR'21] PyTorch code for our paper "Neural Pruning via Growing Regularization"
Stars: ✭ 44 (-87.02%)
Mutual labels:  pruning
SViTE
[NeurIPS'21] "Chasing Sparsity in Vision Transformers: An End-to-End Exploration" by Tianlong Chen, Yu Cheng, Zhe Gan, Lu Yuan, Lei Zhang, Zhangyang Wang
Stars: ✭ 50 (-85.25%)
Mutual labels:  pruning
NaiveNASflux.jl
Your local Flux surgeon
Stars: ✭ 20 (-94.1%)
Mutual labels:  pruning
Soft Filter Pruning
Soft Filter Pruning for Accelerating Deep Convolutional Neural Networks
Stars: ✭ 291 (-14.16%)
Mutual labels:  pruning
bert-squeeze
🛠️ Tools for Transformers compression using PyTorch Lightning ⚡
Stars: ✭ 56 (-83.48%)
Mutual labels:  pruning
SSD-Pruning-and-quantization
Pruning and quantization for SSD. Model compression.
Stars: ✭ 19 (-94.4%)
Mutual labels:  pruning
Filter Pruning Geometric Median
Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration (CVPR 2019 Oral)
Stars: ✭ 338 (-0.29%)
Mutual labels:  pruning
Yolov3v4 Modelcompression Multidatasettraining Multibackbone
YOLO ModelCompression MultidatasetTraining
Stars: ✭ 287 (-15.34%)
Mutual labels:  pruning
sparsify
Easy-to-use UI for automatically sparsifying neural networks and creating sparsification recipes for better inference performance and a smaller footprint
Stars: ✭ 138 (-59.29%)
Mutual labels:  pruning

Keras-surgeon

A library for performing network surgery on trained Keras models. Useful for deep neural network pruning.

Keras-surgeon provides simple methods for modifying trained Keras models. The following functionality is currently implemented:

  • delete neurons/channels from layers
  • delete layers
  • insert layers
  • replace layers

Keras-surgeon is compatible with any model architecture. Any number of layers can be modified in a single traversal of the network.

These kinds of modifications are sometimes known as network surgery which inspired the name of this package.

Background

This project was motivated by my interest in deep learning and desire to experiment with some of the pruning methods I have read about in the research literature.

I created this package because I could not find an easy way to prune neurons from Keras models. I hope it will be useful to others.

Install

Keras-Surgeon is installed from PyPI using pip.

pip install kerassurgeon

If you'd like to install the examples' dependencies:

pip install kerassurgeon[examples]

It is compatible with tensorflow.keras and standalone keras.

Usage

The operations module contains simple methods to perform network surgery on a single layer within a model.
Example usage:

from kerassurgeon.operations import delete_layer, insert_layer, delete_channels
# delete layer_1 from a model
model = delete_layer(model, layer_1)
# insert new_layer_1 before layer_2 in a model
model = insert_layer(model, layer_2, new_layer_3)
# delete channels 0, 4 and 67 from layer_2 in model
model = delete_channels(model, layer_2, [0,4,67])

The Surgeon class enables many modifications to be performed in a single operation.
Example usage:

# delete channels 2, 6 and 8 from layer_1 and insert new_layer_1 before 
# layer_2 in a model
from kerassurgeon import Surgeon
surgeon = Surgeon(model)
surgeon.add_job('delete_channels', layer_1, channels=[2, 6, 8])
surgeon.add_job('insert_layer', layer_2, new_layer=new_layer_1)
new_model = surgeon.operate()

The identify module contains methods to identify which channels to prune.

Examples

Examples are in kerassurgeon.examples.
Both examples identify which neurons to prune using the method described in Hu et al. (2016): those which have the highest Average Percentage of Zeros (APoZ).
Neither example is particularly good at demonstrating the benefits of pruning but they show how Keras-surgeon can be used.
I would welcome any good examples from other users.

Pruning Lenet trained on MNIST

lenet_minst is a very simple example showing the effects of deleting channels from a simple Lenet style network trained on MNIST. It demonstrates using the simple methods from kerasurgeon.operations.

Inception V3 fine-tuned on flowers data-set

This example shows how to delete channels from many layers simultaneously using the Surgeon Class.
It is in two parts:
inception_flowers_tune shows how to fine-tune the Inception V3 model on a small flowers data set (based on a combination of Tensorflow tutorial and Keras blog post).
inception_flowers_prune demonstrates deleting channels from many layers simultaneously using the Surgeon Class.

Limitations

Many commonly used layer types are fully supported. Models containing other layer types may cause errors depending on if the unsupported layers are affected by the operation. Some layers downstream of pruned layers are also affected.

Recurrent layers’ sequence length must be defined.
The model’s input shape must be defined.

License

MIT © Ben Whetton

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].