Keras Activations
Project description
Keras Activations
pip install keract
You have just found a (easy) way to get the activations for each layer of your Keras model (recurrent nets, conv nets, resnets...).
API
from keract import get_activations
get_activations(model, x)
Inputs
modelis akeras.models.Modelobjectxis a numpy array to feed to the model as input. In the case of multi-input,xis of type List. We use the Keras convention (as used in predict, fit...).
Output
- A dictionary containing the activations for each layer of
modelfor the inputx:
{
'conv2d_1/Relu:0': np.array(...),
'conv2d_2/Relu:0': np.array(...),
...,
'dense_2/Softmax:0': np.array(...)
}
The key is the name of the layer and the value is the corresponding output of the layer for the given input x.
Examples
Examples are provided for:
keras.models.Sequential- mnist.pykeras.models.Model- multi_inputs.py- Recurrent networks - recurrent.py
In the case of MNIST with LeNet, we are able to fetch the activations for a batch of size 128:
conv2d_1/Relu:0
(128, 26, 26, 32)
conv2d_2/Relu:0
(128, 24, 24, 64)
max_pooling2d_1/MaxPool:0
(128, 12, 12, 64)
dropout_1/cond/Merge:0
(128, 12, 12, 64)
flatten_1/Reshape:0
(128, 9216)
dense_1/Relu:0
(128, 128)
dropout_2/cond/Merge:0
(128, 128)
dense_2/Softmax:0
(128, 10)
We can even visualise some of them.
A random seven from MNIST
Activation map of CONV1 of LeNet
Activation map of FC1 of LeNet
Activation map of Softmax of LeNet. Yes it's a seven!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keract-1.1.2.tar.gz.
File metadata
- Download URL: keract-1.1.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.2 CPython/3.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73999638b1478de19738039cf9bfe573265e6d39c77187cccbac02cd94544685
|
|
| MD5 |
df4de091767c4249337be8a31f0319df
|
|
| BLAKE2b-256 |
be33f9ae6e91a3bebe98493e3bcdcb19897dc81951262c262ba9105f919792ec
|
File details
Details for the file keract-1.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: keract-1.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.2 CPython/3.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bad97d36b4e826d48d88ae68794d30cb6bf5e08628d782140dea476753b46b79
|
|
| MD5 |
ae2ef1d828534fccce4f46e81cd1b8a0
|
|
| BLAKE2b-256 |
8570012ab03c6d380d7bfaf32a03c0cb3a86bb1eca0aaa4350dc8a1bfba2b63a
|