Neural Network Programming Deep Learning with PyTorch

此部分是b站一个系列Neural Network Programming DeepLearning wit PyTorch的学习笔记,有空就更新,目前以tf学习为主

1. Using CUDA

CUDA is a platform supported by NVIDA and designed for Deep Learning computing, especially parrallel computing, which means those computing can be divided as tiny computing and be worked out by different parts without interference.

import torch
print(torch.__version__)
torch.cuda.is_available()
1.4.0+cpu
False

2. Tensors

2.1 Introduction

If one element can be accessed by n indices at least, it’s an nd-tensor.

Indexes required Computer science Mathmatics
0 number scalar
1 array vector
2 2d-array matrix
n nd-array nd-tensor

2.2 Rank Axes and Shape

  • Rank refers to the number of dimensions present within the tensor, also the least number of indices that we need to access a tensor. For example, the following are the same:
    • rank-2 tensor
    • matrix
    • 2d- array
    • 2d-tensor
  • Axes is always decribed in n*m*q etc. n,m,q describe the length of each axes. Dimensions tell us how many axes a tensor has, and the length of axes tells us the shape.

2.3 Reshaping in PyTorch

Call the reshape() function of the tensor

The shape of the tensor will be changed after reshaping (but not the varible itself), while the elements stay unchanged.

2.4 Example

  1. Define a data structure
dd = [
    [0,1,2],
    [3,4,5],
    [6,7,8]
]
  1. Change the 3*3 matrix to a pytorch tensor
t = torch.tensor(dd)
t
tensor([[0, 1, 2],
        [3, 4, 5],
        [6, 7, 8]])
  1. Get the tensor’s shape
t.shape
torch.Size([3, 3])
  1. Reshape the tensor as an 1*9 tensor
t.reshape(1,9)
tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8]])

Important: Resahping dosen’t change the axes number (the tensor still has two layers), and it dosn’t change the virible’s shape, so the wanted result (after reshaping) should be assigned to another pytorch tensor if it’s wanted.

t.shape # t.shape remains unchanged after t.reshape(1,9)
torch.Size([3, 3])
Neural Network Programming Deep Learning with PyTorchNeural Network Programming Deep Learning with PyTorch thinszx 发布了10 篇原创文章 · 获赞 1 · 访问量 5204 私信 关注
上一篇:UCF Local Programming Contest 2015


下一篇:Dynamic Programming