pytorch
小颖同学要加油哦
这个作者很懒,什么都没留下…
展开
-
pytorch 反向传播backward
设置变量x1, x2, x3 设置函数 z = x1 * x2 + x3 并且对x1进行求导,所以求出的结果因该为x2 requires_grad=True //设置变量是可以求导的 z.backward()//是z进行反向传播 retain_graph = True//可以进行多次的求导 x1 = torch.randn(1, requires_grad=True) print("x1", x1) x2 = torch.randn(1, requires_grad=True) print(".原创 2021-05-25 17:59:29 · 231 阅读 · 0 评论 -
pytorch GPU加速
指定GPU的编号 网络,损失函数,训练的数据,标签需要调入GPU中训练 to.(device) import torch """ net:网络 Loss:loss损失函数 data:数据 label:标签 """ device = torch.device("cuda:0") print(device) device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") print(device) data = data.t原创 2021-05-24 10:38:11 · 93 阅读 · 0 评论 -
pytorch tensor的创建
一、使用实际的数据创建tensor 1、使用list tensor = torch.tensor([[2, 3, 4],[5, 6, 7]]) print(tensor) tensor([[2, 3, 4], [5, 6, 7]]) 2、使用numpy np_array = np.array([[1,2,3],[1,2,3]]) np_to_tensor = torch.from_numpy(np_array) print(np_to_tensor) 二、使用维度来创建te...原创 2021-05-24 10:09:16 · 243 阅读 · 0 评论