主要分为两大部分:
主要包括PyTorch 常用的API:
--torch:torch常用的API
--torchvision:torchvision常用API
torch:
torch包含了多维张量的数据结构以及基于其上的多种数据操作。他也提供了多种工具,其中一些可以更有效地张量和任意类型进行序列化。它有 CUDA 的对应实现,可以在 NVIDIA GPU 上进行张量运算 (计算能力 >=2.0)。
Tensors
torch.is_tensor(obj):如果参数obj是一个PyTorch张量,则返回True。
torch.is_storage(obj):如果obj是一个PyTorch storage对象,则返回Ture。
torch.set_default_tensor_type(t):设置当前tensor的默认数据类型。
>>> torch.tensor([1.2, 3]).dtype # initial default for
floating point is torch.float32 , →
torch.float32
>>> torch.set_default_tensor_type(torch.DoubleTensor)
>>> torch.tensor([1.2, 3]).dtype # a new floating point
tensor , →
torch.float64
torch.numel(input)->int:返回input张量中的元素个数。input(Tensor):输入张量。
>>> a = torch.randn(1,2,3,4,5)
>>> torch.numel(a)
120
>>> a = torch.zeros(4,4)
>>> torch.numel(a)
16
torch.set_printoptions(precision=None, threshold=None,
edgeitems=None, linewidth=None, profile=None)}

设置打印选项。完全参考自
Numpy
。
参数:
-precision:浮点数输出的精度位数(默认为8)
-threshold:阈值,触发汇总显示而不是完全显示(repr)的数组元素的总数(默认为1000)
-edgeitems:汇总显示中,每维(轴)两端显示的项数(默认值为3)
-linewidth:用于插入行间隔的每行字符数(默认为80)。Thresholded matricies will ignore this parameter。
-
profile
:
pretty
打印的完全默认值。可以覆盖上述所有选项
(
默认为
short, full)