-
- 创建张量
- tensor与numpy数组之间的转换
- 索引、连接、切片等
- Tensor操作【add,数学运算,转置等】
- GPU加速
-
自动求导:torch.autograd
-
读取数据集:torch.utils.data
- 抽象类:torch.utils.data.Dataset
- 采用batch、shuffle或者多线程:torch.utils.data.DataLoader
-
- 参数:torch.nn.Parameter()
- 容器:基类、时序
- 卷积层
- 池化层
- 标准化层
- 循环层
- 激活层:torch.nn.ReLU和torch.nn.functional.relu的效果一样
- Linear层
- Dropout层
- 稀疏层
- 距离函数
- 损失函数
-
-
一、Pytorch数据类型
1、Tensor张量:torch.Tensor是一种包含单一数据类型元素的多维矩阵。
(1)创建张量------float型、long型、全0张量、随机正态分布张量


(2)Tensor和numpy之间的转换:
通过a.numpy(),就能将Tensor a转换成numpy数据类型,同时使用torch.from_numpy()就能将numpy转换成tensor,如果需要更改tensor的数据类型,只需要在转换后面加上需要的类型,如想将a的类型转换成float,只需a.float()就可以了。

(3)Tensor的索引、切片、连接、换位:
- 连接:torch.cat(inputs, dimension=0) → Tensor【dimension=0按行连接】
![]()
1 >>> x = torch.randn(2, 3)
2 >>> x
3
4 0.5983 -0.0341 2.4918
5 1.5981 -0.5265 -0.8735
6 [torch.FloatTensor of size 2x3]
7
8 >>> torch.cat((x, x, x), 0)
9
10 0.5983 -0.0341 2.4918
11 1.5981 -0.5265 -0.8735
12 0.5983 -0.0341 2.4918
13 1.5981 -0.5265 -0.8735
14 0.5983 -0.0341 2.4918
15 1.5981 -0.5265 -0.8735
16 [torch.FloatTensor of size 6x3]
17
18 >>> torch.cat((x, x, x), 1)
19
20 0.5983 -0.0341 2.4918 0.5983 -0.0341 2.4918 0.5983 -0.0341 2.4918
21 1.5981 -0.5265 -0.8735 1.5981 -0.5265 -0.8735 1.5981 -0.5265 -0.8735
22 [torch.FloatTensor of size 2x9]
View Code