Git Product home page Git Product logo

tensorhue's Introduction

TensorHue

Warning

TensorHue is currently in alpha. Expect bugs. We appreciate any feedback!

TensorHue - tensors, visualized

TensorHue is a Python library that allows you to visualize tensors right in your console, making understanding and debugging tensor contents easier.

You can use it with your favorite tensor processing libraries, such as PyTorch, JAX, and TensorFlow, and a large set of related libraries, including Numpy, Pillow, torchvision, and more.

TensorHue automagically detects which kind of tensor you are visualizing and adjusts accordingly:

tensor types

Getting started

Install TensorHue with pip:

pip install tensorhue

Using TensorHue is easy, simply import TensorHue after importing the library of your choice:

import torch
import tensorhue

That's it! You can now visualize any tensor by calling .viz() on it in your Python console:

t = torch.rand(20,20)
t.viz() ✅

You can also visualize them like this:

tensorhue.viz(t) ✅

Numpy arrays can only be visualized with tensorhue.viz(...) (because np.ndarray is immutable):

np.array([1,2,3]).viz() ❌
tensorhue.viz(np.array([1,2,3])) ✅

Images

Pillow images can be visualized in RGB using .viz():

from torchvision.datasets import CIFAR10
dataset = CIFAR10('.', dowload=True)
img = dataset[0][0]
img.viz() ✅
image visualization

By default, images get downscaled to the size of your terminal, but you can make them even smaller if you want:

img.viz(max_size=(40,40)) ✅

Custom colors

You can pass along your own ColorScheme when visualizing a specific tensor:

from tensorhue import ColorScheme
from matplotlib import colormaps

cs = ColorScheme(colormap=colormaps['inferno'],
                 true_color=(255,255,255),
                 false_color=(0,0,0))
t.viz(cs)

Alternatively, you can overwrite the default ColorScheme:

tensorhue.set_printoptions(colorscheme=cs)

Advanced colormaps and normalization

By default, TensorHue normalizes numerical values between 0 and 1 and then applies the matplotlib colormap. If you want to use diverging colormaps such as coolwarm or bwr and the value 0 to be mapped to the middle of the colormap, you need to specify the normailzer, e.g. matplotlib.colors.CenteredNorm:

from matplotlib.colors import CenteredNorm
cs = ColorScheme(colormap=colormaps['bwr'],
                 normalize=CenteredNorm(vcenter=0))
t.viz(cs)

You can also specify the normalization range manually, for example when you want to visualize a confusion matrix where colors should be mapped to the range [0, 1], but the actual values of the tensor are in the range [0.12, 0.73]:

conf_matrix.viz(vmin=0, vmax=1, scale=3)
confusion matrix

The scale parameter scales up the 'pixels' of the tensor so that small tensors are easier to view.

tensorhue's People

Contributors

epistoteles avatar

Stargazers

Enes Erdogan avatar Tobias Hoffmann avatar Nikola avatar Francesco Taioli avatar Erdi Kılıç avatar Tomasz Dróżdż avatar Dan Turkel avatar  avatar Jon Baer avatar Omkar Dige avatar Jae Hee Lee avatar Alif Munim avatar Valle avatar Sushil Awale avatar Malek avatar Aditi Mhatre  avatar Mohamed Rissal Hedna avatar Giuseppe Cianci avatar Robert Geislinger avatar  avatar Diana Rueda avatar

Watchers

 avatar Kostas Georgiou avatar Tobias Hoffmann avatar

tensorhue's Issues

Can't import - no module named 'tensorhue.connectors'

Here's what I see when I try to import in an IPython session:

----> 1 import tensorhue

File ~/GradSchool/VHLab/rftk/env/lib/python3.11/site-packages/tensorhue/__init__.py:5
      3 from tensorhue.colors import COLORS, ColorScheme
      4 from tensorhue._print_opts import PRINT_OPTS, set_printoptions
----> 5 from tensorhue.connectors._numpy import NumpyArrayWrapper
      6 from tensorhue.connectors._torch import _tensorhue_to_numpy_torch
      7 from tensorhue.connectors._jax import _tensorhue_to_numpy_jax

ModuleNotFoundError: No module named 'tensorhue.connectors'

Don't you need an __init__.py file in the connectors directory for Python's module system to recognize it? I haven't tried to make a package in a while but I vaguely recall needing to do that.

[FEATURE]: Support for Older Python Versions (<3.9)

Can you please make it compatible with python <3.9? I changed the required parts in the setup.cfg etc. to make it installable in python 3.8 and installed it from setup.py, and it works as far as I can tell. (Though I had to change type hints list -> List, tuple -> Tuple etc.).

I would have created a pull request but I could not run the tests (due to jax being a headache to install in my machine)

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.