摘要: 张量 Tensors 1、torch.is_tensor torch.is_tensor(obj) 用法:判断是否为张量,如果是 pytorch 张量,则返回 True。 参数:obj (Object) – 判断对象 例子: torch.is_tensor(torch.rand(2,3)) True 阅读全文
posted @ 2021-10-20 23:17 多发Paper哈 阅读(478) 评论(0) 推荐(0) 编辑
摘要: import torch #cuda是否可用 torch.cuda.is_available() 结果: True #返回当前设备索引 torch.cuda.current_device() 结果: 0 #返回GPU的数量 torch.cuda.device_count() 结果: 1 #返回gpu 阅读全文
posted @ 2021-10-20 18:37 多发Paper哈 阅读(324) 评论(0) 推荐(0) 编辑
摘要: Example1: for input, target in dataset: optimizer.zero_grad() output = model(input) loss = loss_fn(output, target) loss.backward() optimizer.step() Ex 阅读全文
posted @ 2021-10-20 17:36 多发Paper哈 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 参考:官方 1. 均匀分布 torch.nn.init.uniform_(tensor, a=0.0, b=1.0) 解释: Fills the input Tensor with values drawn from the uniform distribution $\mathcal{U}(a, 阅读全文
posted @ 2021-10-20 16:53 多发Paper哈 阅读(1217) 评论(0) 推荐(0) 编辑
摘要: 1 导入实验所需要的包 import numpy as np import torch from torch import nn from torch.utils import data import matplotlib.pyplot as plt #解决内核挂掉 import os os.env 阅读全文
posted @ 2021-10-20 13:47 多发Paper哈 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 假设有如下模型 net = nn.Sequential(nn.Linear(2, 1)) 现在要获取其参数值和参数名称 方法一: for parm in net[0].parameters(): print(parm) 结果: Parameter containing: tensor([[-0.07 阅读全文
posted @ 2021-10-20 11:12 多发Paper哈 阅读(1934) 评论(0) 推荐(0) 编辑
摘要: Tensor 和 NumPy 相互转换常使用 numpy() 和 from_numpy() 。需要注意的是: 这两个函数所产生的 Tensor 和 NumPy 中的数组共享相同的内存(所以他们之间的转换很快),改变其中一个时另一个也会改变! Tensor 转 Numpy 数组 a = torch.o 阅读全文
posted @ 2021-10-20 10:51 多发Paper哈 阅读(802) 评论(0) 推荐(0) 编辑
摘要: 参考:官方文档 源码 官方文档 nn.Sequential A sequential container. Modules will be added to it in the order they are passed in the constructor. Alternatively, an o 阅读全文
posted @ 2021-10-20 10:33 多发Paper哈 阅读(4572) 评论(0) 推荐(2) 编辑
Live2D