from nbdev.showdoc import *
from fastcore.test import test_eq
from lovely_grad import monkey_patch
ποΈ View as RGB images
rgb
rgb (x:tinygrad.tensor.Tensor, denorm:Any=None, cl:Any=False, gutter_px:int=3, frame_px:int=1, scale:int=1, view_width:int=966, ax:Optional[matplotlib.axes._axes.Axes]=None)
Type | Default | Details | |
---|---|---|---|
x | Tensor | Tensor to display. [[β¦], C,H,W] or [[β¦], H,W,C] | |
denorm | typing.Any | None | Reverse per-channel normalizatoin |
cl | typing.Any | False | Channel-last |
gutter_px | int | 3 | If more than one tensor -> tile with this gutter width |
frame_px | int | 1 | If more than one tensor -> tile with this frame width |
scale | int | 1 | Scale up. Canβt scale down. |
view_width | int | 966 | target width of the image |
ax | typing.Optional[matplotlib.axes._axes.Axes] | None | Use this Axes |
Returns | RGBProxy |
rgb(image)
=2) rgb(image, scale
= Tensor.stack([image]*2)
two_images two_images
Tensor[2, 3, 196, 196] n=230496 xβ[-2.118, 2.640] ΞΌ=-0.388 Ο=1.073 CPU Realized ADD
= ( [0.485, 0.456, 0.406], # Mean
in_stats 0.229, 0.224, 0.225] ) # std
[=in_stats) rgb(two_images, denorm
# Make 8 images with progressively higher brightness and stack them 2x2x2.
= (Tensor.stack([image]*8) + Tensor(np.linspace(-2, 2, 8).astype(np.float32)).reshape(8,1,1,1))
eight_images = (eight_images
eight_images 1]).reshape(1,3,1,1))
.mul(Tensor(in_stats[0]).reshape(1,3,1,1))
.add(Tensor(in_stats[0,1)
.clip(2,2,2,3,196,196)
.reshape(
) eight_images
Tensor[2, 2, 2, 3, 196, 196] n=921984 xβ[0., 1.000] ΞΌ=0.382 Ο=0.319 CPU Realized NEG
rgb(eight_images)
# You can do channel-last too:
1, 2, 0), cl=True) rgb(image.permute(