蓝灯123

导航

2022年1月21日 #

一个全连接网络模型,激活函数是ReLU, 具有一个隐藏层且没有偏差, 经过训练可以使用欧几里得误差根据x来预测y。

摘要: from __future__ import print_function import torch import torch.nn as nn import torchvision.datasets as dsets import torchvision.transforms as transfo 阅读全文

posted @ 2022-01-21 15:32 蓝灯123 阅读(134) 评论(0) 推荐(0) 编辑

class myFirstNetwork(nn.Module):

摘要: import torchimport torch.nn as nnimport torchvision.datasets as dsetsimport torchvision.transforms as transformsfrom torch.autograd import Variablefro 阅读全文

posted @ 2022-01-21 15:00 蓝灯123 阅读(54) 评论(0) 推荐(0) 编辑

获取数据模板

摘要: import torch import torch.nn as nn import torchvision.datasets as dsets import torchvision.transforms as transforms from torch.autograd import Variabl 阅读全文

posted @ 2022-01-21 14:47 蓝灯123 阅读(31) 评论(0) 推荐(0) 编辑

2022年1月20日 #

一个稍微复杂的梯度计算例子

摘要: 多自变量的函数,求梯度 x = torch.randn(3, requires_grad=True) # x 中存了三个变量 x1,x2,x3 y = x + 2 z = y * y * 3 z = z.mean() # 求导 z.backward() print(x.grad) # dz/dx # 阅读全文

posted @ 2022-01-20 23:37 蓝灯123 阅读(122) 评论(0) 推荐(0) 编辑

梯度计算简单例子

摘要: 下面a56爆大奖在线娱乐们来看一个简单的例子, 定义x, y, z三个变量, 其中x是需要计算梯度的. x = torch.tensor([1.0], requires_grad=True) y = torch.tensor([2.0]) z = torch.tensor([2.0]) # 定义运算 f1 = 2*x 阅读全文

posted @ 2022-01-20 23:07 蓝灯123 阅读(728) 评论(0) 推荐(0) 编辑

pyTorch求梯度实例

摘要: import torch x=torch.tensor(3.0, requires_grad=True) z=torch.tensor(4.0, requires_grad=True) y=x**2+z**3 y.backward() print('dy/dx = 2x:', x.grad) pri 阅读全文

posted @ 2022-01-20 22:29 蓝灯123 阅读(37) 评论(0) 推荐(0) 编辑

可以用 torch.fron_numpy 将 Numpy 数组转化为 PyTorch 张量。

摘要: 1 import torch 2 from torch.autograd import Variable 3 import numpy as np 4 x = np.array([[1,2,3],[2,3,4]]) 5 xt = torch.from_numpy(x) 6 print(xt) 阅读全文

posted @ 2022-01-20 15:25 蓝灯123 阅读(59) 评论(0) 推荐(0) 编辑

matlab图的坐标名称、字体、字号

摘要: matlab图的坐标名称、字体、字号 1 ylim([0.5,2]); 2 xlabel('J');ylabel('U'); 3 set(get(gca,'XLabel'),'FontSize',16,'Fontname', 'Courier New','FontWeight','bold','Fo 阅读全文

posted @ 2022-01-20 09:42 蓝灯123 阅读(421) 评论(0) 推荐(0) 编辑