Visualize linear regions in neural networks
Project description
Python interface for Regioncam
Regioncam is a rust library and python package for visualizing linear regions in a neural network. Regioncam works by tracking the output of all neural network layers in the regions where these outputs are linear. The inputs are in a 1 or 2 dimensional space.
Usage
import regioncam
import numpy as np
# Create a regioncam object, with the region [-1..1]^2
rc = regioncam.Regioncam(size=1)
# Apply a linear layer
rng = np.random.default_rng()
weight = rng.standard_normal((2, 30), dtype=np.float32)
bias = rng.standard_normal((30,), dtype=np.float32)
rc.linear(weight, bias)
# Apply a relu activation function
rc.relu()
# Write to svg
rc.write_svg("example.svg")
# Inspect regions
print(f"Created {rc.num_faces} regions")
for face in rc.faces:
print(face.vertex_ids)
Produces the following svg file:
Arrays passed to regioncam, such as weights and biases must be numpy arrays or torch tensors with dtype float32.
Regioncam also has limited support for torch nn layers:
net = torch.nn.Sequential(
torch.nn.Linear(2,30),
torch.nn.ReLU(),
torch.nn.Linear(30,30),
torch.nn.ReLU(),
)
rc.add(net)
See examples/ for an example of visualizing a trained torch network.
The following layer types are supported:
- ReLU
- LeakyReLU
- Linear
- Sequential
- Identity
- Dropout (treated as Identity)
- residual
Installation
The regioncam python package can be installed with pip,
pip install regioncam
To compile locally, use
pip install ./regioncam-python
or
cd regioncam-python
maturin build --release
More information
Regioncam is similar to Splinecam, but the algorithm is different. See the github repository for the details.
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 regioncam-0.5.2.tar.gz.
File metadata
- Download URL: regioncam-0.5.2.tar.gz
- Upload date:
- Size: 337.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1ed3deed3646eeb6ebf78f63375df5d138435de9de0b9905b5f8d69f1048f69
|
|
| MD5 |
0cb958bbe1296db289d75c9eecc5be57
|
|
| BLAKE2b-256 |
a5e593d5ca6cf356f7a4b428b2711306fae3c8e7078f55102fb932e66cac7117
|
File details
Details for the file regioncam-0.5.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: regioncam-0.5.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f9346c4d19f7948f9a099183a0efd1ca1a49f932444e4f499fd85493e851584
|
|
| MD5 |
3de9cbbbb4b468c45a608dcfe6fff355
|
|
| BLAKE2b-256 |
7dd3d7dac2d11e927c8f1c83d7c60b178076dea9ebc9bcf9c821d8980316b682
|