Practical overview
When it fits
Use it when a trained Keras model needs structural edits, such as channel pruning or layer changes, and its layer types and shape requirements fit the operation.
Who it is for
- Developers modifying trained models built with standalone Keras or tensorflow.keras.
- Practitioners exploring neuron or channel pruning and other structural model changes.
Documented uses
- Delete selected neurons or channels from a layer.
- Delete, insert or replace layers in an existing model.
- Batch multiple structural edits into one operation.
- Use channel-identification methods to help choose channels for pruning.
Requirements & limits
The public GitHub repository identifies the project as open source and specifies the MIT license. Installation is documented through pip.
- The model input shape must be defined, and recurrent layers require a defined sequence length.
- Unsupported layer types affected by an operation may cause errors; downstream layers can also be affected by pruning.
- The included examples show how to use pruning operations, but the README says they do not particularly demonstrate pruning benefits.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install Keras-Surgeon
Install Keras-Surgeon for use with a Keras model.
Before you start
- Python environment with pip.
- A
tensorflow.kerasor standalonekerasinstallation.
Steps
Install the library with the command below.
pip install kerassurgeonTo install the example dependencies as well, use the command below.
pip install kerassurgeon[examples]
Expected outcome
Keras-Surgeon is installed and can be used to modify trained Keras models.
Guide limitations
- The library supports many commonly used layer types; the README notes that other layer types may be limited.
Prune channels and insert a layer with Surgeon
Apply channel deletion and layer insertion to a model in one Surgeon operation.
Before you start
- An existing Keras model, referenced as
model. - The model layers referenced as
layer_1andlayer_2, and a new layer referenced asnew_layer_1.
Steps
Create a Surgeon instance with
surgeon = Surgeon(model).Queue channel deletion with
surgeon.add_job('delete_channels', layer_1, channels=[2, 6, 8]).Queue insertion before
layer_2withsurgeon.add_job('insert_layer', layer_2, new_layer=new_layer_1).Apply the queued changes with
new_model = surgeon.operate().
Expected outcome
The example produces `new_model` with the specified channels deleted from `layer_1` and `new_layer_1` inserted before `layer_2`.
Guide limitations
- The README says many commonly used layer types are fully supported but warns that models containing other layer types may have limitations.
- The example assumes the model and referenced layers already exist; it does not document model loading or evaluation.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 15 November 2026
- Original website title
- BenWhetton/keras-surgeon · Official homepage title · retained in its source language

