Keras Model Extract
This is a small utility library to access Keras/TensorFlow model's structure/tree and do stuff with it.
Currently there isn't a straight-forward way to do this without manually going through the model layers.
It currently supports:
- Model tree iteration (BFS-like)
- Accessing node parents, node children, node output type
- Accessing source layers
Node properties:
children: children nodes (sub-layers)parent_names: unique names of parent nodesshape: layer output shapename: unique layer name (from TF/Keras)__layer: reference to the instance of the layer (ifinclude_layer_refisTrue)
How it works:
- It creates a pure Python tree clone of your model which is easy to walk through.
Installation
This package has no depenedencies.
pip install keras-model-extract
Example use
This examples show how to iterate through a model and print all the nodes.
>>> from keras_model_extract import copy_model_tree, iterate
>>> from keras.applications.vgg16 import VGG16
>>> model = VGG16()
>>> nodes = copy_model_tree(model)
>>> nodes
{'input_1': input_1, 'block1_conv1': block1_conv1, 'block1_conv2': block1_conv2, 'block1_pool': block1_pool, 'block2_conv1': block2_conv1, 'block2_conv2': block2_conv2, 'block2_pool': block2_pool, 'block3_conv1': block3_conv1, 'block3_conv2': block3_conv2, 'block3_conv3': block3_conv3, 'block3_pool': block3_pool, 'block4_conv1': block4_conv1, 'block4_conv2': block4_conv2, 'block4_conv3': block4_conv3, 'block4_pool': block4_pool, 'block5_conv1': block5_conv1, 'block5_conv2': block5_conv2, 'block5_conv3': block5_conv3, 'block5_pool': block5_pool, 'flatten': flatten, 'fc1': fc1, 'fc2': fc2, 'predictions': predictions}
>>> nodes['input_1'].children
[block1_conv1]
>>> nodes['block4_pool'].parent_names
['block4_conv3']
>>> nodes['block4_pool'].shape
(None, 14, 14, 512)
>>> iterate(nodes['input_1'], lambda layer: print(layer))
input_1
block1_conv1
block1_conv2
block1_pool
block2_conv1
block2_conv2
block2_pool
block3_conv1
block3_conv2
block3_conv3
block3_pool
block4_conv1
block4_conv2
block4_conv3
block4_pool
block5_conv1
block5_conv2
block5_conv3
block5_pool
flatten
fc1
fc2
predictions
Metadata
Release files for keras-model-extract 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| keras_model_extract-0.0.2.tar.gz | 3.9 kB | Without provenance | Details for keras_model_extract-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| keras_model_extract-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for keras_model_extract-0.0.2-py3-none-any.whl |
Total release size: 8.4 kB
Release files / keras_model_extract-0.0.2.tar.gz
| Download URL | keras_model_extract-0.0.2.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90bd7d6610ce6352c3aa1d4d598a2b59e56b18a706cb4247c451ef4cbfae3e49
|
|
BLAKE2b-256 checksum How to use checksums |
31927cc62557ce0ecd38158098b663bc61df207b15481663452c51812e2718a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.5
|
Release files / keras_model_extract-0.0.2-py3-none-any.whl
| Download URL | keras_model_extract-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
424f9970be55ef9149f98674b82cb2a5d69e87880709c3735b4e9314a06a5374
|
|
BLAKE2b-256 checksum How to use checksums |
56b8d4ab98902b498a9e7b0c6fb27824b6f2262b002768ba428819d61be9d7e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.5
|
Security for keras-model-extract 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.