Skip to content

ichko/aesthetic-tensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎨 Aesthetic-Tensor

A simple fluent API for tensor visualization and debugging.

Presented at EuroSciPy 2024 as a Poster

Install

pip install git+https://github.com/ichko/aesthetic-tensor

Usage

Instead of trying to decipher the default __repr__ of a tensor

T = torch.rand(3, 100, 100)
T
>> tensor([[[0.9531, 0.3449, 0.8426,  ..., 0.3743, 0.4693, 0.6880],
            [0.2732, 0.3456, 0.6288,  ..., 0.3619, 0.8134, 0.2392],
            [0.8204, 0.2013, 0.9769,  ..., 0.7117, 0.0643, 0.4224],
            ...,
  • ugh...

aesthetify you tensors like this

from aesthetic_tensor import monkey_patch_torch

monkey_patch_torch()  # monkey patch torch.Tensor

T.ae
>> float32<3, 100, 100>∈[0.000, 1.000] | μ=0.499, σ=0.288
  • much better

Documentation

  • T.ae.imshow()

    torch.rand(10, 10).ae.imshow()

    Random imshow

  • T.ae.hist()

    torch.rand(10, 10).ae.hist()

    Random hist

  • T.ae.displot

    (torch.stack([torch.randn(1000) / 2,  (torch.randn(1000) + 4)])).ae.displot

    Random bimodal

  • T.ae.ploy()

    torch.rand(30).ae.plot(figsize=(6, 1))

    Random hist

  • T.ae.gif()

    torch.rand(2, 3, 10, 10).ae.N.zoom(10).gif(fps=1)

    gif-1 gif-2

But my tensors are frequently batched

Calling the .N property on an AestheticTensor will give you an AestheticCollection, pulling the leftmost dimension as a batch dimension. You have the same interface as before, you just apply every transformation to each element.

An example will make everything much more clear.

torch.rand(3, 2, 30).ae.N
>>[3](~float32<2, 30>∈[0.032, 0.977] | μ=0.514, σ=0.293)

now you can choose how to plot each of the 3 elements of shape <2, 30>.

torch.rand(3, 2, 30).ae.N.imshow(figsize=(6, 1))

Random batched

  • Use this notebook as a library of examples.

Resources

  • A lot for inspiration for this project came from this library lovely-tensors.