Today I learned
·1 min
On the AI/Fastai front:
- If
x
is atorch.Tensor
andx.shape
istorch.Size([4, 3, 5])
, it meansx
contains 4 2D matrices with 3 rows and 5 columns. Also,x
is 3D matrix, the technical term for which would be a rank-3 tensor. - When images are represented using PyTorch
tensor
s, the first dimension corresponds to the number of channels in it. (For e.g., an RGB image will contain 3 channels and, therefore, the first element in the tensorshape
will be3
.)- Matplotlib’s
imshow
function expects number of channels at the end and you can modify atensor
to that by applying thepermute
function.
- Matplotlib’s