pytorch MSELoss参数详解「建议收藏」

pytorch MSELoss参数详解「建议收藏」pytorchMSELoss参数详解importtorchimportnumpyasnploss_fn=torch.nn.MSELoss(reduce=False,size_average=False)a=np.array([[1,2],[3,8]])b=np.array([[5,4],[6,2]])input=torch.autograd.Variable(to…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

pytorch MSELoss参数详解

import torch
import numpy as np
loss_fn = torch.nn.MSELoss(reduce=False, size_average=False)
a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

loss_fn = torch.nn.MSELoss(reduce=False, size_average=True)
a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
loss_fn = torch.nn.MSELoss(reduce=True, size_average=False)
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
loss_fn = torch.nn.MSELoss(reduce=True, size_average=True)
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
loss_fn = torch.nn.MSELoss()##reduce=True, size_average=True
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

loss_fn = torch.nn.MSELoss(reduction = 'none')
a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

loss_fn = torch.nn.MSELoss(reduction = 'sum')
a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

loss_fn = torch.nn.MSELoss(reduction = 'none')
a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)

loss_fn = torch.nn.MSELoss(reduction = 'elementwise_mean')
a=np.array([[1,2],[3,8]])
b=np.array([[5,4],[6,2]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(loss)



版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/192085.html原文链接:https://javaforall.net

(0)
上一篇 2026年1月19日 下午3:43
下一篇 2026年1月19日 下午4:15


相关推荐

  • Maven压缩插件YUI Compressor使用介绍

    Maven压缩插件YUI Compressor使用介绍简介这篇文章主要介绍了Maven压缩插件YUICompressor使用介绍以及相关的经验技巧,文章约18810字,浏览量165,点赞数5,值得参考!使用这个插件主要有两个作用:减少资源文件体积,提高移动端页面加载速度。对关键的前端代码进行一定的代码混淆,保护知识产权。使用说明:使用YUICompressor压缩JS和CSS。需要Maven2.0及以上工程。默认情…

    2022年7月18日
    36
  • jar包下载网站「建议收藏」

    jar包下载网站「建议收藏」1.这里可以查询POM信息和JAR包下载https://www.kumapai.com/open/query/?querytype=title&querykey=cglib1.https

    2022年7月4日
    26
  • OpenClaw小龙虾-Skill安装教程及推荐安装列表

    OpenClaw小龙虾-Skill安装教程及推荐安装列表

    2026年3月14日
    2
  • 圆柱体的立方计算公式_圆柱体积公式是什么

    圆柱体的立方计算公式_圆柱体积公式是什么圆柱的体积是六年级下册第三单元的知识点。利用圆柱的体积公式计算圆柱的体积显得尤为重要。让我们一起来复习一下吧!第一个计算圆柱的体积公式新课是怎样引出圆柱的体积的呢?你还记得那个操作不?选自人教版六年级下册数学课本人教版课本25页是将圆柱切割拼凑为近似长方体从而得到我们最常用的体积公式V=Sh例题1:如图,求圆柱的体积给s和h求圆柱的体积V=50.24×10=502.4平方厘米例题2:一个圆柱形蓄水…

    2026年2月2日
    4
  • pi可以卸载重新安装吗_pip删除安装包

    pi可以卸载重新安装吗_pip删除安装包打开python安装目录下的Scripts文件夹,在空白处shift+鼠标右键,选择在此处打开命令窗口,在弹出的窗口中执行命令easy_install.exepip即可。如果python安装目录下的Scripts目录中有没有easy_install.exe参见http://blog.csdn.net/la6nf/article/details/7…

    2022年10月19日
    5
  • tree 命令安装

    tree 命令安装一、用yum安装tree命令yuminstall-ytree二、下载包安装下载安装包yuminstall-ywgetwgethttp://mama.indstate.edu/users/ice/tree/src/tree-1.8.0.tgztar-zxvftree-1.8.0.tgz-C/opt/softcdtree-1.8.0/yuminstall-ymakemakeinstall测试使用,命令:treemake:gcc:命令未找到make:**

    2022年7月25日
    18

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号