Math Computation and Reshape
Автор: The City Of Knowledge
Загружено: 2022-10-18
Просмотров: 19
Описание:
Welcome back. Last time, we discussed the dimensionality of the tensors. Today, we're going to have a quick look at the mathematical operations with tensors like multiplication, addition, and so on. First, we define two tensors of size three. It's a one tensor one, two, three, the second one, four, five, six, and then, we can multiply tensors. So, if we call "matmul", let's execute. So we see, we are printing out of the tensors, we have the first float tensor of size three, the second one of the same size, and the result of matmul is scalar. Why is this so? Because mammal is actually scalar multiplication which we know from linear algebra. So, the second one is an interesting operation that we can do with tensors is concatenation. First, we define two tensors from random numbers of size two and then, we are calling "torch. cat", and "torch. cat". It will concatenate tensors and by default, if we don't specify the axis, it will stock the tensors. Maybe we should execute this. All right now, so you can see that we have here one tensor which has two rows and five columns of size two by five. We have the second tensor which has three rows, five columns, and three by five, and if you call the cat to concatenate, it will stock these two matrices or two tensors and we have them a tensor of size five by five. Another way is to concatenate tensors column-wise. For this, we have to specify the axis. So if we specify the axis of one as a second parameter, it will align the tensors, so it will concatenate column-wise. So, we can see what it looks like. So, we have one tensor of size two by three, the second one of size two by five, and if we call a cat with an axis of one, we will get a tensor of size two by eight. So, if we define the wrong number, it will not be able to execute this concatenation, I mean the wrong number of rows for example. Let's define the second tensor of size three by five. Instead of two by five, and then we execute this, so we get error, and inconsistent tensor sizes. It's pretty simple. Now, we're going to look how to reshape the tensors. It's actually a variation which we usually need. Let's assume we have RGB images. We have 64,000 images that we can, for example, analyze with our convolutional neural network. And here, if we want to reshape this tensor, so initially we have a tensor of shape (64,000, 3, 28, 28) what could it be? It could be here on the second position, it could be a number of color channels, three, it's actually a usual way to define images. And the last two, we'll use 28, 28, this is the image size. Now, let's assume we have to reshape the whole tensor or this is a tensor, actually torch number, we'll create a tensor, we'll have to reshape it, and we want to introduce a batch size for example. So, we want to see how many batches we can construct out of 64,000 images. So, we have here on the first position, we will define the batch size. Now, we can left unchanged the number of color channels which is three and the image size 28, 28. But here, we can infer the second dimension, we can left unfilled, so with minus one, and it will cost the PyTorch will automatically infer the correct second dimension. It takes some time because it calls a random number. Sometimes it takes a moment. So now, we see batch size 32, and then it has to insert 2,000, it's great. So, if you multiplied 2,000 by 32, you will get exactly 64,000. Okay. I hope you enjoyed the session and see you next time. Enjoy. Bye bye.
The initial lectures series on this topic can find in the below links:
What is SystemML (1/2)
• What is SystemML (1/2)
What is SystemML (2/2)
• What is SystemML (2/2)
Introduction to Pytorch:PyTorch Installation
• Introduction to Pytorch:PyTorch Installation
PyTorch Packages
• PyTorch Packages
Tensor Creation and Visualization of Higher Dimensional Tensors
• Tensor Creation and Visualization of Highe...
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: