Uses manim to visulize a sequence of tensors. This repository is currently used for personal academic paper drawing purpose. If you are interested in codevelop this further, please get in touch.
pip install Tensor-Spectacle
- LaTex installed
- Whatever other packages on which
manim
is based
To visualize a list of tensors, you can easily create a class as shown below:
from tensorspec.scenes.tensors_distribution import TensorVisualizationScene
# make some random 4D tensors (batch, channel, h, w)
random_shapes = [(randint(1, 2), randint(3, 6), randint(3, 6), randint(3, 6)) for _ in range(3)]
tensors = [torch.rand(shape) for shape in random_shapes]
labels = [f"Random Tensor {i}" for i in range(len(tensors))]
# make scene
class Example(TensorVisualizationScene):
def construct(self):
super().construct(tensors=tensors, labels=labels, duration_each=0.8, duration_gap=1, engine="matplotlib")
# render
with tempconfig(
{
"use_opengl_renderer": True,
"disable_caching": True,
"write_to_movie": True,
"resolution": "1080p",
"renderer": "cairo", # "opengl", "cairo"; opengl is faster but manim community at the moment has some issues
"fps": 60,
}
):
scene = Example()
scene.render()
Then run your script, and watch it happen.
At the moment, using a tensor with channel size less than 3 is recommanded.
An example is at _test.py
This project is licensed under the CC BY-NC License.
The initial motivation was to visualize the training dynamics of biomimetic neurons. However, I realized this could be useful in many scenarios. I will continue updating this as long as I work with neural networks. Contributions are welcome.
Tested on Ubuntu 20.04 (see /.github/workflows)
@misc{Tensor-Spectacle2023,
author = {Don Yin},
title = {Tensor-Spectacle: Visualizing a Sequence of Tensors},
year = {2023},
publisher = {GitHub},
journal = {GitHub Repository},
howpublished = {\url{https://github.com/YourUsername/Tensor-Spectacle}},
}