Tensor Visualizer
This is a package to visualize tensor data in notebooks.
Install
pip install tensor-visualizer
Usage
You can use this widget in a notebook to visualize tensor data.
The widget supports numpy ndarrays, PyTorch and Tensorflow tensors,
as well as MLX tensors.
from tensor_visualizer import TensorVisualizer
# Visualize a 4-dimensional numpy array.
import numpy as np
data = np.random.randn(5, 10, 10, 10)
widget = TensorVisualizer(data)
widget
from tensor_visualizer import TensorVisualizer
# Visualize a 4-dimensional torch tensor.
import torch
data = torch.randn((5, 10, 10, 10))
widget = TensorVisualizer(data)
widget
You can name dimensions with the names argument:
TensorVisualizer(data, names=["batch", "channel", "height", "width"])
and label indices for the dimensions with the labels argument:
TensorVisualizer(
data,
names=["batch", "channel", "height", "width"],
labels=[["b1", "b2", "b3"], ["ch1", "ch2"]]
)
By default the widget infers the color scale automatically from your data. To configure the color scale, you can set the scale_domain, scale_type, and scale_scheme properties:
# Set the scale domain to [1, 100], log scale,
# and use the viridis color scheme.
w = TensorVisualizer(data, scale_domain=[1, 100], scale_type="log", scale_scheme="viridis")
# You can also set it after creating the widget
w.scale_domain = [0, 1]
If you are using inferred scales, you can access the inferred scale properties with current_scale_domain, current_scale_type, and current_scale_scheme. These properties are available only after the widget has been shown.
You may use the permute argument the re-order the tensor dimensions in the visualization. For instance, permute=[2, 0, 1, 3] shows dimension 2 first, then dimension 0, 1, and 3. The last two dimensions are used in the heatmap.
Parameters
| Name | Description |
|---|---|
tensor |
The tensor to visualize. |
names |
The names for dimensions in the tensor. |
labels |
Lists of labels for dimensions in the tensor. |
default_views |
Specify the default views for each dimension, supported options are: slice, small-multiples, min, max, and mean. |
scale_domain |
Specify the scale domain. If unspecified, the widget will infer the domain automatically. |
scale_type |
Specify the scale type (linear or log). The default is linear. |
scale_scheme |
Specify the scale color scheme. If unspecified, the widget will infer the scheme automatically. |
permute |
Permute the order of the tensor's dimensions. |
Development
This project consists of a Svelte library for the frontend component, and Python code for the widget.
To setup for frontend development, run:
npm install
npm run dev
You'll get a development server (usually at http://localhost:5173) that hosts an demo page of the frontend component.
To build the frontend package, run:
npm run build
To build the Python package, run:
hatch build
To develop the widget, you can start a Jupyter Lab instance and load the example notebooks in the examples folder:
hatch run jupyter lab
Metadata
Release files for tensor-visualizer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tensor_visualizer-0.1.0.tar.gz | 172.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tensor_visualizer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 230.6 kB
Release files / tensor_visualizer-0.1.0.tar.gz
| Download URL | tensor_visualizer-0.1.0.tar.gz |
|---|---|
| Size | 172.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01b7f5b82a6dd19b7f56b206c38dd48ea9b773c6de2a6413a6bacef8b3b367db
|
|
BLAKE2b-256 checksum How to use checksums |
4ca40ec318fd2e79d4c7b2b6b85d8e8fb0934b496debf10d12dbd5d0c38b9f6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.0
|
Release files / tensor_visualizer-0.1.0-py3-none-any.whl
| Download URL | tensor_visualizer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 58.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7bdeacef9b443403b3712f6c4b6279c122034d4b296a7768197a275f2d0f871
|
|
BLAKE2b-256 checksum How to use checksums |
d701c895ba3966f7f0d8d1efb68fbb65b6d4ff53a5b4124e328e8d49a46382f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.0
|