Skip to content

shawwn/sparkvis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sparkvis

See here for usage instructions. Maybe someday I'll write a real readme, but not at 2am on a Thursday.

Ok fine, I'll write a readme. This is a library for visualizing tensors in a plain Python REPL using sparklines. I was sick of having to install jupyter on servers just to see a damn tensor.

E.g. the FFT of MNIST looks like this:

Quickstart

pip3 install -U sparkvis
python3
from sparkvis import sparkvis as vis
vis(foo)

foo can be a torch tensor, tf tensor, numpy array, etc. It supports anything with a .numpy() method.

vis(a, b) will put 'a' and 'b' side by side. For example,

import numpy as np
from sparkvis import sparkvis as vis
x = np.random.rand(7,7)
vis(x, np.zeros_like(x), np.ones_like(x))

will print this:

▅▅▅▄▄▄▂▂▂▅▅▅▄▄▄▅▅▅▅▅▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
▄▄▄▃▃▃▃▃▃▆▆▆▁▁▁▃▃▃███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
▆▆▆▇▇▇▆▆▆▂▂▂▇▇▇▅▅▅▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
███▇▇▇▃▃▃▇▇▇▄▄▄▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
▆▆▆▅▅▅▇▇▇▅▅▅███▆▆▆▄▄▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
▂▂▂▇▇▇▇▇▇▆▆▆▆▆▆▁▁▁▃▃▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
▅▅▅▇▇▇▆▆▆▅▅▅▅▅▅▁▁▁▇▇▇▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████████████████████
7x21 min=0.0 max=1.0
<sparkvis.Sparkvis object at 0x10230f310>

You can pass to_string=True if you want the string instead of printing to stdout. Or you can pass file=f like the normal python print function.

Note on Tensorflow in Graph mode

Currently this library only supports Tensorflow in eager mode, since those are the only tensors that have a .numpy() method. Graph-based tensorflow tensors use .eval() rather than .numpy(). (Sorry, I'll get around to it sometime, otherwise PRs welcome.)

License

MIT.

About

Visualize tensors in a plain Python REPL using Sparklines

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages