Neural Network Signal Processing
Project description
Neural Network Signal Processing
nsp is a Python package for extracting and visualizing activation patterns of PyTorch neural networks. It can
- extract the computational graph of a neural network as a directed graph.
- extract the activation pattern generated by an input of a neural network.
- compute the Fourier transform of an activation pattern (signal) in a neural network (directed graph) based on [1] and [2].
- visualize activation patterns and their Fourier coefficients.
Visualization of the activation pattern
Visualization of the Fourier coefficients
Dependencies
Installation requires pytorch, networkx, and numpy. Some functions will use scipy and/or matplotlib.
Installation
Use the package manager pip to install nsp.
pip install nsp
Usage
Get your network as torch.nn.Module
and a valid input.
import nsp
import torch
import torch.nn as nn
class Network(nn.Module):
def __init__(self):
super(Network, self).__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=2, kernel_size=2)
self.conv2 = nn.Conv2d(in_channels=2, out_channels=8, kernel_size=2)
self.fc1 = nn.Linear(1*4*8, 8)
def forward(self, x):
x = torch.sigmoid(self.conv1(x))
x = torch.sigmoid(self.conv2(x))
x = x.view(-1, 1*4*8)
x = self.fc1(x)
return x
network = Networks()
image = torch.tensor([[[[-6, -1, -2, 5],
[-3, -6, 5, 4],
[ 2, 5, -6, 3],
[ 5, 0, 1, -6]]]], dtype = torch.float)
Extract the activation pattern.
activations = nsp.Activations(network, image)
Extract the graph of your neural network. NNGraph
extends networkx.DiGraph
.
graph = nsp.NNGraph(activations)
Transform the activation pattern into its spectrum.
spectrum = graph.transform(activations)
Visualize the activation pattern and the spectrum. Pick your favorite cmap_style
from matplotlib colormaps.
nsp.Visualizer.visualize_pattern(activations, pdf_filepath='activations.pdf', scale='layernorm', cmap_style='viridis')
nsp.Visualizer.visualize_pattern(spectrum, pdf_filepath='spectrum.pdf', scale='layernorm', cmap_style='viridis')
Visualization of the activation pattern
Visualization of the spectrum
For more details check out the tutorials and read the documentation.
License
Developed by Felipa Schwarz (c) 2021
References
[1] Markus Püschel, Bastian Seifert, and Chris Wendler. Discrete signal processing on meet/join lattices. IEEE Transactions on Signal Processing, 2021.
[2] Bastian Seifert, Chris Wendler and Markus Püschel. A Causal Shift and Fourier Transform for Directed Acyclic Graphs. Submitted for publication, 2021.
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
File details
Details for the file nsp-0.0.16.tar.gz
.
File metadata
- Download URL: nsp-0.0.16.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.7.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad133bf7334c48a3f99ec506931b6a25f4b9d3eb5d9658e065d3de424da807dc |
|
MD5 | c84434a6607efed44949c6e5ccb06009 |
|
BLAKE2b-256 | b94a481fe2533d274c3cdb5d41f5f2296edf0b1d18d0ff15e6682787398c4a3f |
File details
Details for the file nsp-0.0.16-py3-none-any.whl
.
File metadata
- Download URL: nsp-0.0.16-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.7.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51fdde37a9168190c438b4441719955b6ef8fe2f3231c90ce4703096b2e6ec1b |
|
MD5 | 980899997d591561656b877cefdd0bb4 |
|
BLAKE2b-256 | 506d69344129291cec49a0bd9c69f546993272e3d5991d8166a9da0b0ac38ad8 |