from torch_snippets import *
= np.random.rand(100, 100)
im show(im)
Show
Show is intended to show numpy-arrays/PIL-images
=4) show(im, sz
Show will even accept pytorch Tensors and show them as images, even if they are on GPU and have channels first
It can accept bounding boxes as tuples of (x,y,X,Y)
which can be integers (i.e., absolute coordinates) or fractions (between \([0,1]\)). There’s provision to give bb_colors and texts as well
=[(0, 0, 0.5, 0.35), (0, 0.2, 0.35, 0.95)])
show(im, bbs
=[(0, 0, 0.5, 0.35), (0, 0.2, 0.35, 0.95)], bb_colors=["r", "g"])
show(im, bbs
show(
im,=[(0, 0, 0.5, 0.35), (0, 0.2, 0.35, 0.95)],
bbs=["b", "g"],
bb_colors=["bb1", "bb2"],
texts=10,
sz=15,
text_sz )
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
It can also read a file path directly and display the image
"../docs/images/company_logo_big.png", sz=3) show(
if the input is not an image or string, show
will simply display the given input as intended by jupyter notebook
= pd.DataFrame(np.random.rand(100, 2))
df show(df)
0 | 1 | |
---|---|---|
0 | 0.242478 | 0.929517 |
1 | 0.971890 | 0.506750 |
2 | 0.139826 | 0.753227 |
3 | 0.864799 | 0.524166 |
4 | 0.563610 | 0.135709 |
... | ... | ... |
95 | 0.379874 | 0.639771 |
96 | 0.993731 | 0.811343 |
97 | 0.621683 | 0.763054 |
98 | 0.844509 | 0.915156 |
99 | 0.314272 | 0.392418 |
100 rows × 2 columns
= Chart(df).mark_circle().encode(x="0:Q", y="1:Q")
chart show(chart.interactive())
Subplots
display multiple images Subplots is a wapper around plt.subplots that accepts a list of images, number of columns as nc and additional kwargs
from torch_snippets import subplots
= [np.random.rand(100, 100) for _ in range(16)]
ims
=4, sz=5) subplots(ims, nc
subplots(
ims,=2,
nc=(5, 15),
sz="RANDOM IMAGES",
suptitle=[f"random_{i}" for i in range(16)],
titles )