当前位置: 首页 > news >正文

南康网站建设公司b2b和b2c是什么意思

南康网站建设公司,b2b和b2c是什么意思,阿里巴巴网站推广怎么做,移动吉生活app下载前提知识:[Pytorch] 前向传播和反向传播示例_友人小A的博客-CSDN博客 目录 简介 叶子节点 Tensor AutoGrad Functions 简介 torch.autograd是PyTorch的自动微分引擎(自动求导),为神经网络训练提供动力。torch.autograd需要对…

前提知识:[Pytorch] 前向传播和反向传播示例_友人小A的博客-CSDN博客

目录

简介

叶子节点

Tensor AutoGrad Functions


简介

torch.autograd是PyTorch的自动微分引擎(自动求导),为神经网络训练提供动力。torch.autograd需要对现有代码进行最少的更改——声明需要计算梯度的Tensor的属性requires_grad=True。截至目前,PyTorch仅支持 FloatTensor类型(half、float、double和bfloat16)和 ComplexTensor(cfloat、cdouble)的autograd。【信息来自官网】

叶子节点

叶子结点是离散数学中的概念。一棵树当中没有子结点(即度为0)的结点称为叶子结点,简称“叶子”。 叶子是指出度为0的结点,又称为终端结点。

在pytorch中,什么是叶子节点?根据官方定义理解如下。

  • 所有requires_grad为False的张量,都约定俗成地归结为叶子张量
  • requires_grad为True的张量, 如果他们是由用户创建的,则它们是叶张量(leaf Tensor), 表明不是运算的结果,因此grad_fn=None

示例1

def test_training_pipeline2():input_data = [[4, 4, 4, 4],[9, 9, 9, 9]]  # 2x4input = torch.tensor(input_data, dtype=torch.float32)  # requires_grad=Falseoutput = torch.sqrt(input)target_data = [1, 2, 3, 4]target = torch.tensor(target_data, dtype=torch.float32)  # requires_grad=Falseloss_fn = torch.nn.MSELoss()loss = loss_fn(input=output, target=target)print("\ninput.is_leaf:", input.is_leaf)print("output.requires_grad:", output.requires_grad)print("output.is_leaf:", output.is_leaf)print("target.is_leaf:", target.is_leaf)print("loss.requires_grad:", loss.requires_grad)print("loss.is_leaf:", loss.is_leaf)

样例2

def test_training_pipeline2():input_data = [[4, 4, 4, 4],[9, 9, 9, 9]]  # 2x4input = torch.tensor(input_data, dtype=torch.float32)  # requires_grad=Falseoutput = torch.sqrt(input)output.requires_grad_(True) # requires_grad=Truetarget_data = [1, 2, 3, 4]target = torch.tensor(target_data, dtype=torch.float32)  # requires_grad=Falseloss_fn = torch.nn.MSELoss()loss = loss_fn(input=output, target=target)print("\ninput.is_leaf:", input.is_leaf)print("output.requires_grad:", output.requires_grad)print("output.is_leaf:", output.is_leaf)print("target.is_leaf:", target.is_leaf)print("loss.requires_grad:", loss.requires_grad)print("loss.is_leaf:", loss.is_leaf)

样例3

 

def test_training_pipeline5():input = torch.rand(1, requires_grad=True)output = torch.unique(input=input, sorted=True, return_inverse=False, return_counts=False, dim=None)print("\ninput.is_leaf:", input.is_leaf)print("output.requires_grad:", output.requires_grad)print("output.is_leaf:", output.is_leaf)output.backward()

样例4

def test_training_pipeline3():input_data = [[4, 4, 4, 4],[9, 9, 9, 9]]  # 2x4input_a = torch.tensor(input_data, dtype=torch.float32, requires_grad=True)input_b = torch.tensor(input_data, dtype=torch.float32, requires_grad=True)output = torch.ne(input_a, input_b)print("\ninput_a.is_leaf:", input_a.is_leaf)print("input_b.is_leaf:", input_b.is_leaf)print("output.dtype:", output.dtype)print("output.requires_grad:", output.requires_grad)print("output.is_leaf:", output.is_leaf)output.backward()   # 报错

 

 

样例5

def test_training_pipeline7():input_data = [[4, 4, 4, 4],[9, 9, 9, 9]]  # 2x4input_a = torch.tensor(input_data, dtype=torch.float32, requires_grad=True)input_b = torch.tensor(input_data, dtype=torch.float32)    output = torch.add(input_a, input_b)print("\ninput_a.requires_grad:", input_a.requires_grad)print("input_b.requires_grad:", input_b.requires_grad)print("output.requires_grad:", output.requires_grad)print("output.is_leaf:", output.is_leaf)grad = torch.ones_like(output)input_b[0][0] = 10 input_a[0][0] = 10 output.backward(grad)

 样例6

def test_training_pipeline9():x = torch.tensor([1.0], requires_grad=True)y = x + 2z = 2 * y		# <-- dz/dy=2y[0] = -2.0print("\nx.is_leaf:", x.is_leaf)print("y.is_leaf:", y.is_leaf)print("z.is_leaf:", z.is_leaf)print("\nx.requires_grad:", x.requires_grad)print("y.requires_grad:", y.requires_grad)print("z.requires_grad:", z.requires_grad)z.backward()def test_training_pipeline9():x = torch.tensor([1.0], requires_grad=True)y = x + 2z = y * y  # <-- dz/dy= 2*yy[0] = -2.0print("\nx.is_leaf:", x.is_leaf)print("y.is_leaf:", y.is_leaf)print("z.is_leaf:", z.is_leaf)print("\nx.requires_grad:", x.requires_grad)print("y.requires_grad:", y.requires_grad)print("z.requires_grad:", z.requires_grad)z.backward()

 

Tensor AutoGrad Functions

  1. Tensor.grad

  2. Tensor.requires_grad

  3. Tensor.is_leaf

  4. Tensor.backward(gradient=None, reqain_graph=None, create_graph=False)

  5. Tensor.detach()

  6. Tensor.detach_()

  7. Tensor.retain_grad()

http://www.khdw.cn/news/63098.html

相关文章:

  • 主播网站开发seo排名快速刷
  • 政府门户网站建设内容seo好学吗入门怎么学
  • 玉泉路做网站专业培训大全
  • 网站分析及推广方案盐城seo营销
  • 永久免费做网站app企业网站设计思路
  • 中英文企业网站系统网站设计公司官网
  • 营销自己的网站互联网推广员是做什么
  • 安康免费做网站公司优化营商环境心得体会个人
  • 外贸网站怎么做优化网站域名怎么查询
  • 免费代理服务器ip地址企业网站seo方案案例
  • 大连企业网站设计欣赏谷歌seo网站优化
  • 做网站开视频网站友情链接平台网站
  • 日本不良网站正能量大豆推广普通话手抄报内容大全资料
  • 网站建设到维护营销策划推广公司
  • wordpress整站主题西安seo网站管理
  • 有哪些做的很漂亮的网站优化关键词的公司
  • 教做发绳的网站深圳有实力的seo公司
  • 重庆网站建设外包哪家好百度霸屏推广靠谱吗
  • 即墨有做网站的吗百度文章收录查询
  • 小型行业网站建设维护成本网络广告
  • 做的网站如何更换网站模板seo是什么职业岗位
  • 外贸网站seo优化常德论坛网站
  • 政府网站建设的项目描述百度竞价推广的技巧
  • 怎么推广游戏叫别人玩外贸网站seo推广教程
  • 在线网页下载seo优化诊断工具
  • 咸阳做网站的公司大众点评seo关键词优化
  • 网站建设行业发展史免费刷粉网站推广免费
  • wordpress 图片并列sem和seo有什么区别
  • 给别人做网站被诉侵权排名优化软件
  • 网站开发难题谷歌网站优化推广