![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PyTorch 基础
csdn-WJW
这个作者很懒,什么都没留下…
展开
-
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none) ERROR: No
运行 PyTorch 代码时报错: ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)ERROR: No matching distribution found for PIL解决方法下载 Pillow 离线安装包 .whl 文件https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow使用下载的 .whl 离线安装原创 2020-12-26 12:07:30 · 2368 阅读 · 0 评论 -
PyTorch 代码中 GPU 编号与 nvidia-smi 命令中的 GPU 编号不一致问题解决方法
问题描述nvidia-smi -L 查看可用 GPU 列表GPU 0: Quadro Kxxx (UUID: GPU-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)GPU 1: GeForce RTX xxxx (UUID: GPU-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)pytorch 代码中查看可用 GPU 列表device = torch.device("cuda:1" if torch.cuda.is_available()原创 2020-12-24 12:43:41 · 11082 阅读 · 2 评论 -
PyTorch 自定义 Dataset 及训练集、测试集划分方法
实例 1:自定义数据集类,torch.utils.data.random_split() 划分训练集和测试集,通过普通遍历方式使用自定义数据集中的样本import numpy as npimport torchfrom torch.utils.data import Dataset, DataLoaderrandom_data = np.random.randn(10,3)print(random_data)print("#"*len(random_data))class MyDat.原创 2020-12-15 19:29:53 · 27297 阅读 · 8 评论 -
PyTorch 中 LSTM 的 output、h_n 和 c_n 之间的关系
LSTM 简介官方文档:https://pytorch.org/docs/stable/generated/torch.nn.LSTM.htmlh_n:最后一个时间步的输出,即 h_n = output[:, -1, :](一般可以直接输入到后续的全连接层,在 Keras 中通过设置参数 return_sequences=False 获得)c_n:最后一个时间步 LSTM cell 的状态(一般用不到)实例实例:根据红框可以直观看出,h_n 是最后一个时间步的输出,即是 h_n = ou原创 2020-12-15 16:27:03 · 8737 阅读 · 7 评论 -
安装 Tesla K20c 时:This device cannot start. (Code 10) Insufficient system resourc
1、问题描述戴尔 Precision Tower 7810 工作站 Windows 10 系统安装 Tesla K20c 和 Quadro K620 双显卡,想让 Quadro K620 尽负责显示,Tesla K20c 只负责计算,但查查看 Window 10 的【设备管理器】时发现 Tesla K20c 显卡设备出现叹号,查看属性,提示如下信息“该设备无法启动。 (代码 10) 系统资源不够,无法完成 API。”# 对应的英文是:“This device cannot start. (Cod原创 2020-08-02 21:34:49 · 3818 阅读 · 0 评论 -
PyTorch 去除值为 1 的维度
1. 方法torch.squeeze(input, dim=None, out=None) → Tensor官方文档:https://pytorch.org/docs/master/generated/torch.squeeze.html参数说明:input (Tensor):输入的张量dim (int, optional) :可选参数,如果不指定,该方法会把所有值为 1 的维度移除,如果指定,该方法则指移除指定的那个维度out (Tensor, optional) :可选,指定输出的张量原创 2020-07-15 19:50:03 · 8866 阅读 · 0 评论 -
PyTorch 中常见的基础型张量操作 .numpy()、.item()、.detach()、.gpu()、.cpu()
.numpy()官方文档:https://pytorch.org/docs/stable/tensors.html#torch.Tensor.numpy功能:将张量转换为共享底层存储的 n 维 numpy 数组.item()官方文档:https://pytorch.org/docs/stable/tensors.html#torch.Tensor.cpu功能:将张量的值转换为标准的 Python 数值,只有当张量仅含一个元素时才能使用它.detach()官方文档:http..原创 2020-07-13 00:14:12 · 2865 阅读 · 0 评论 -
PyTorch 使用 TensorBoard 中的 writer.add_scalar 与 writer.add_scalars 的区别
writer.add_scalar()功能:将标量添加到 summary参数:tag (string):数据标识符scalar_value (float or string/blobname):要保存的数值global_step (int):全局步值walltime (float):可选参数,用于记录发生的时间,默认为 time.time()writer.add_scalars()功能:添加多个标量数据到 summary 中参数:main_tag (string):tag原创 2020-07-12 21:04:52 · 39022 阅读 · 6 评论 -
PyTorch 结合 zip 和 enumerate 方法循环遍历数据和标签实例
实例代码>>> import torch>>> data = torch.randn(10)>>> data# tensor([-1.4227, 0.4803, -0.1308, -0.9972, -1.2646, -0.7575, -0.6185, 0.3919, -0.9820, -0.1905])>>> labels = torch.linspace(1,10,10)>>> lab原创 2020-07-12 16:49:25 · 2359 阅读 · 0 评论 -
torch.manual_seed() 和 torch.cuda.manual_seed() 功能及实例
功能设置固定生成随机数的种子,使得每次运行该 .py 文件时生成的随机数相同设置方法CPU:torch.manual_seed(整数)官方文档:https://pytorch.org/docs/stable/torch.html?highlight=manual_seed#torch.manual_seedGPU:torch.cuda.manual_seed(整数)官方文档:https://pytorch.org/docs/stable/cuda.html?highlight=ma原创 2020-06-01 10:39:05 · 10275 阅读 · 3 评论