【Pytorch警告】Using a target size (torch.Size([])) that is different to the input size (torch.Size([1])

这篇具有很好参考价值的文章主要介绍了【Pytorch警告】Using a target size (torch.Size([])) that is different to the input size (torch.Size([1])。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

我代码中造成警告的语句是:

value_loss = F.mse_loss(predicted_value, td_value) # predicted_value是预测值,td_value是目标值,用MSE函数计算误差

原因:mse_loss损失函数的两个输入Tensor的shape不一致。经过reshape或者一些矩阵运算以后使得shape一致,不再出现警告了。文章来源地址https://www.toymoban.com/news/detail-515278.html

到了这里,关于【Pytorch警告】Using a target size (torch.Size([])) that is different to the input size (torch.Size([1])的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 128]

    因为用到了BatchNorm,所以batch_size要大于1,drop_last 参数设置为True。 如果是两个GPU训练,batch_size改为4。 参考 ValueError: Expected more than 1 value per channel when training, got input size [1, 16, 1, 1](解决方案) Pytorch遇到报错Expected more than 1 value per channel when training, got input size torch.Size

    2024年01月16日
    浏览(14)
  • win_size exceeds image extent. Either ensure that your images are at least 7x7; or pass win_size ex

    win_size exceeds image extent. Either ensure that your images are at least 7x7; or pass win_size ex

    在进行超分辨率重建后想计算SSIM和PSNR,最开始发现导入compare_psnr,compare_ssim居然报错了, 上网一查发现版本更新换成了structural_similarity和peak_signal_noise_ratio。 解决 之后又发现  好家伙,这么一大段话,我估计 multichannel=True也已经不用了,报错中说 set channel_axis to the axis numb

    2024年02月08日
    浏览(11)
  • jenkins执行jmeter时,报Begin size 1 is not equal to fixed size 5

    jenkins执行jmeter时,报Begin size 1 is not equal to fixed size 5

    jenkins执行jmeter脚本的时候一直提示如下错误: 原因是jenkins版本2.4以上要求的jdk版本11-19,jmeter命令报告生成需要的jdk版本1.8,属于jdk的版本兼容问题 解决方法:下载jdk1.8并解压,然后在jmeter路径/bin下的jmeter文件中添加jdk路径

    2024年02月15日
    浏览(11)
  • kafka消费/发送消息,消息过大报错解决whose size is larger than the fetch size 1048576

    kafka消费/发送消息,消息过大报错解决whose size is larger than the fetch size 1048576

    一、kafka消费报错原因 问题原因一:个是kafka本身的配置没有调整到上限 问题原因二:就是我们自己写python消费kafka代码的时候没有参数配置没有限制 RecordTooLargeError: (\\\"There are some messages at [Partition=Offset]: {TopicPartition(topic=\\\'psadad\\\', partition=1): 75} whose size is larger than the fetch size 1

    2024年02月07日
    浏览(12)
  • QObject: Cannot create children for a parent that is in a different thread

    在Qt的官方文档,大家知道有两种方式使用 QThread。 You can use worker objects by moving them to the thread using QObject::moveToThread(). Another way to make code run in a separate thread, is to subclass QThread and reimplement run(). 在使用MoveToThread这种方式时,经常会遇到下面类似的问题: QObject: Cannot create child

    2024年02月06日
    浏览(7)
  • 运行错误:view size is not compatible with input tensor‘s size and stride (at least

    运行错误:view size is not compatible with input tensor‘s size and stride (at least

    python运行报错: view size is not compatible with input tensor\\\'s size and stride (at least one dimension spans acros 出现这个原因主要就是因为v iew()需要 Tensor 中的元素地址是连续的,因为可能出现Tensor不连续的情况,修改为: 在.view前加 .contiguous() ,使其变为连续就ok。    

    2024年02月11日
    浏览(10)
  • Pytorch中报错RuntimeError: The size of tensor a (60) must match the size of tensor b (56)

    Pytorch中报错RuntimeError: The size of tensor a (60) must match the size of tensor b (56)

    最近在学习YOLOV5的时候,刚开始遇到了如下的问题: 这可能是因为5.0的工程下载了个6.1的模型,所以不匹配 yolov5s.pt [https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt] 下载下来替换掉工程文件夹里的yolov5s.pt文件 发现下面这个问题直接消失了! 顺利完成 如果对你有用麻

    2024年02月01日
    浏览(13)
  • Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.

    Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.

    新建表或者修改表varchar字段长度的时候,出现这个错误 大概意思就是行大小太大,不能超过65535 长度改为21842就正常了,这是为什么? 最终我们执行正确的SQL语句 这里的21842长度是怎么来的? 首先它是什么意思?表示21842字符 首先来了解几个规则,对我们的字符数有影响的

    2024年02月05日
    浏览(12)
  • 积跬步至千里 || PyTorch 中 shape 和 size 属性的区别

    在深度学习中,张量 Tensor 和 向量 array 有相似之处,不同的在于 Tensor 兼具了求导的属性。张量和向量一样,可以表示多维矩阵,也同样都有 shape 和 size 属性。 PyTorch 中 shape 可以计算出各个维数的个数,即表示多维矩阵的形状; PyTorch 中 size() 可通过参数计算出特定维度上的

    2024年02月12日
    浏览(12)
  • RuntimeError: shape ‘[-1, 784]‘ is invalid for input of size 68076

    在应用torch进行测试时,有可能出现这种错误: RuntimeError: shape \\\'[-1, 784]\\\' is invalid for input of size 68076 这个错误通常是由于输入数据的大小与模型期望的输入大小不匹配导致的。具体地说,在这个错误信息中, [-1, 784] 表示输入张量的形状是一个二维张量,第一个维度大小是 -1,

    2024年02月12日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包