PyTorch是使用GPU和CPU优化的深度学习张量库。这篇博客记录如何使用pyTorch初步搭建神经网络。
基于pyTorch的NN:用张量表示数据,用计算图搭建神经网络,用会话执
行计算图,优化线上的权重(参数),得到模型。
张量:张量就是多维数组(列表),用“阶”表示张量的维度。
数据类型
python | pytorch |
---|---|
Int | IntTensor of size() |
float | FloatTensor of size() |
Int array | IntTensor of size [d1,d2,…] |
Float array | FloatTensor of size [d1,d2,…] |
string | ont-hot or Embedding(Word2Vec,glove) |
pyTorch内建的数据类型
Data tyoe | dtype | CPU tensor | GPU tensor |
---|---|---|---|
32-bit floating point | torch.float32 or torch.float | torch.FloatTensor |
torch.cuda.FloatTensor |
64-bit floating point | torch.float64 or torch.double | torch.DoubleTensor |
torch.cuda.DoubleTensor |
16-bit floating point | torch.float16 or torch.half | N/A | torch.cuda.HalfTensor |
8-bit integer (unsigned) | torch.uint8 | torch.ByteTensor |
torch.cuda.ByteTensor |
8-bit integer (signed) | torch.int8 | torch.CharTensor |
torch.cuda.CharTensor |
16-bit integer (signed) | torch.int16 or torch.short | torch.ShortTensor |
torch.cuda.ShortTensor |
32-bit integer (signed) | torch.int32 or torch.int | torch.IntTensor |
torch.cuda.IntTensor |
64-bit integer (signed) | torch.int64 or torch.long | torch.LongTensor |
torch.cuda.LongTensor |
原文:https://www.cnblogs.com/lyszyl/p/12116710.html