Understanding Rank 3 Tensors and Beyond
Understanding Rank 3 Tensors and Beyond
of rank 0 tensors.
Rank 2 tensors gave us a list of rank 1 tensors.
Let's see if the pattern holds
as we move up to rank 3 and beyond.
With rank 3, we are close to our limit
of being able to easily visualize tensors.
Rank 3 means we now have 3 different axis
we have to move through to identify each magnitude.
The easiest way to image this is with a normal color photo.
Photos have a red channel, a green channel
and a blue channel for the color of each pixel.
Each of these channels measures a specific magnitude
for a specific point along the horizontal
and vertical axis.
The red channel alone is a rank 2 tensor
because it's a collection of individual magnitudes
for the matrix it represents.
However, that's just 1 channel.
We also have a green channel.
This also measures a magnitude for each pixel
in the image.
This makes green another rank 2 tensor,
describing the same set of points.
The blue channel does likewise.
Since we have common underlying rank 2 features,
which are the exact pixels,
but multiple features per feature,
which are our red, green and blue channels,
we now have a rank 3 tensor.
Let's see this in our virtual world again.
Looking at this collection of blocks,
we can see 3 channels, which are the magenta blocks,
orange blocks and light blue blocks.
Each color of block is still a unique rank 2 tensor
but they go together to better describe the object
we're trying to represent.
We have a list of rank 2 tensors
that all describe the same object.
You don't have to just have 3 layers.
2 will work, as will more than 3.
Yes graphics folks, I heard you thinking, what about CMYK?
Which is Cyan, Magenta, Yellow,
and black for the rest of us.
CMYK is another way to represent colors in images,
but it is 4 channels rather than 3.
However, this is still a rank 3 tensor.
Remember, rank and dimensions are not the same.
That's why we also have shape to describe our tensors.
Let's count the axis we have to traverse
to find the magnitude of a specific pixel.
First, we have to select a vertical location,
that's 1 axis, then we have to select
a horizontal location, that's 2 axis,
then we select a color channel, which is 3 axis.
That allows us to see, or count in this case,
the magnitude, so this is still a rank 3 tensor.
You also don't necessarily need all of the channels
to be colors.
Your fourth channel could be distance of the object
from the camera, which would give you a depth channel.
You could also add on non-color layers,
like X-ray or sonograms.
If you had some reliable way of measuring it,
you could add the most hardness of the object
at each pixel.
The possibilities are nearly limitless.
All of these, even combined,
would still be a rank 3 tensor,
because they would be different features
and magnitudes of each underlying pixel.
I wanna show you a rank 4 tensor
which will help us extrapolate the higher rank tensors.
Each time we've moved up a rank,
we've added a new axis to traverse,
which is really just a new nested list.
When training a model, you'll wanna pass a few objects,
called examples, at a time to the model
to help the model generalize rather than memorize.
This collection of examples is called a batch.
It will be a list of different individual objects,
but collectively, they will all represent the concept
you're trying to have the model learn.
Using our 3 color channel rank 3 tensors
representing images,
this might be a bunch of pictures of cats.
You'd create a short list of these images
to have the model learn what a generic cat looks like.
This would simply be a list, or a row,
of rank 3 tensors.
Taking what you learned from moving up
from rank 1 to rank 2,
can you guess what a rank 5 tensor would look like?
It would be a list of rank 4 tensors
which would also be a matrix of rank 3 tensors.
1 notable higher rank tensor you will probably run into
eventually is video data.
Just like you're watching right now.
You'll have a time axis for the order of the frames,
the height and width of the images,
multiple color channels and if you wanna get crazy,
maybe even some audio channels as well.
That's a list of rank 3 tensors,
making it a rank 4 tensor.
If you then batch video data, you end up with a list
of rank 4 tensors, which makes it a rank 5 tensor.
However, we're not gonna work with any video data
in this course, because it won't be on the exam.
You just wouldn't have enough time
to train a video processing model
in 5 hours on your personal computer.
You're not gonna see a huge amount of tensors
above rank 4 or 5, basically ever.
It's hard to wrap your head around what something
even higher rank would represent
because there are just not that many examples of them
in real life.
Since we're trying to create models for real concepts,
it makes sense to structure the data
in a similar real way.
So with that, we've explored what a tensor is,
which is a mathematical representation
of magnitudes of features of an object.
Hopefully that makes a lot more sense to you now.
Great job making it all the way through tensors.
This is some pretty mind bending stuff,
so come back to these videos again later
if you wanna refresher.
It took me a long time to wrap my head around this stuff
and if you keep at it, you'll get it too.
The most important concepts you'll need to know
are rank and shape, which is why we spent so much time here.
Understanding what those mean
will help you be more efficient in both your model building
and your data preparation.