Expected object of scalar type Long but got scalar type Float

PyTorch中遇到的RuntimeError: expected scalar type Double but found Float错误的解决方法 然而,在编写复杂的深度学习模型时,可能会出现其他导致这个错误的情况,需要根据具体问题进行调试和处理。总结起来,遇到这个错误时,首先要定位到出错的位置,确定期望的数据类型和实际的数据类型不匹配。然后根据错误的原因选择合适的解决方法,包括检查模型的定义、确保输入数据类型匹配以及操作过程中数据类型的一致性。如果在定义模型时指定了Double类型,而在后续的计算或训练过程中提供了Float类型的输入,就会触发该错误。在使用PyTorch进行训练或推断时,我们需要确保输入数据的类型与模型期望的类型一致。 阅读详情

背景:训练模型的时候报错Expected object of scalar type Long but got scalar type Float

解决:

方法一:
targets =torch.LongTensor(targets)
方法二:
targets = targets.to(self.device,dtype=torch.int64)

 

ZYNQ软件复位重启、程序跳转的实现方法(Multiboot) 目录一、增加FSBL的调试信息 一、增加FSBL的调试信息 启动过程的调试信息如下: Xilinx First Stage Boot Loader Release 2016.4 Jan 19 2020-10:35:00 Devcfg driver initialized Silicon Version 3.1 Boot mode is QSPI Single Flash Informat... 阅读详情

相关推荐

告别纸上谈兵:在Xilinx Artix-7 FPGA上实测RGMII接口,从ILA抓包到PC Ping通全流程记录

本文详细记录了在Xilinx Artix-7 FPGA平台上实现RGMII接口的全过程,包括硬件配置、Vivado工程设置、双沿数据转换代码实现以及ILA波形分析。通过实测数据包捕获和PC端Ping测试,验证了千兆以太网通信的稳定性和可靠性,为工业通信网关等应用提供了实用参考。

weixin_33701251的博客 288

Expected object of scalar type Float but got scalar type Double for argument

引言 该问题的原因是,数据的类型不匹配所导致的 解决方式 更改数据类型 如: X_trainTensor–> X_trainTensor.float() When the error is RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #4...

JY丫丫 2305

YOLOv11垃圾检测实战:从零搭建带GUI的智能分类系统(附完整数据集)

本文详细介绍了如何从零开始构建一个基于YOLOv11的智能垃圾检测系统,并集成图形化界面。内容涵盖数据集构建与增强、模型选型与轻量化改进(如引入注意力机制),以及使用PyQt5开发稳定GUI的完整流程,旨在解决实际部署中精度与速度的平衡问题,为环保科技等应用场景提供可落地的解决方案。

650

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target'

在用pytorch的时候,报错RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target'。研究了一下,发现是关于label的错误。修改办法总结一下: 1、RuntimeError: Expected object of scalar type Long b...

记录、分享、合作、共赢 5万+

四路独立可控供电USB 2.0智能集线器设计

USB集线器是连接外设的基础接口设备,其供电管理能力直接影响系统可靠性与远程运维效率。传统HUB仅提供固定VBUS输出,缺乏端口级电源控制机制,难以实现软复位、故障隔离与功耗优化。本方案基于USB 2.0协议透明转发原理,通过硬件级电子负载开关(如MT9700)与独立MCU(ESP32-C3)协同,构建具备四路独立限流(680mA)、纳秒级通断响应、WiFi/MQTT远程管控能力的智能供电架构。技术价值体现在协议无侵入、控制域与数据域物理隔离、默认安全上电策略等工程实践要点,广泛适用于工业远程调试、实验室设

weixin_36289742的博客 195

LEF 5.8 Language Reference学习笔记

您可以在一个 LEF 文件中定义所有元件库信息,但这样会产生一个复杂且难以管理的大文件。相反,您可以将信息分为两个文件,一个是 "technology "LEF 文件,另一个是 "cell library "LEF 文件。

yajuan的专栏 4108

RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #4 'mat1'

       1在学习《动手学深度学习》(Dive-into-DL-PyTorch)的时候。出现了改错误。        RuntimeError: Expected object of scalar type Float but got scalar typ...

嘤嘤怪赚钱养妈妈 2294

以TMS320F28069为例,如何使用CCS建立DSP工程文件

以TMS320F28069为例,本文主要介绍了使用CCS建立DSP工程的流程

Honglong 2556

Pytorch遇到的问题及解决方案 - 更新ing

1、安装完成后,不能import torch,提示 ImportError: dlopen: cannot load any more object with static TLS 解决办法:有很多答案都说是将import torch放在import cv2之前,但我试了之后还是不能解决,最后是通过在jupyter notebook中可以直接import torch。我是通过mobarxterm...

Tsingzao的博客 5万+

Unity四部曲(核心)

需要先改成Cube复杂的展开留到unity进阶再说。

ultraman1234566的博客 2797

在abaqus中利用point-based 来快捷定义螺栓连接

abaqus中可以通过point-based方式定义连接点的位置,并对连接方式进行定义,可以进行螺栓连接的模拟。 可以通过逐点输入坐标或导入外部的坐标位置 也可以通过阵列的方式定义点 定义完点后就利用create fasteners,选择point-based,选取刚才创建好的点阵列,然后定义连接的属性,如下图 定义connector section时,类型选择translator,相当于只有1方向可以动,定义弹性模量以及破坏准则。 案例操作 假如有两个板,通过...

fiber_tape的博客 7353

Pytorch出现:Expected object of scalar type Long but got scalar type Float for argument问题

Pytorch出现:Expected object of scalar type Long but got scalar type Float for argument问题 Expected object of scalar type Long but got scalar type Float for argument Expected object of scalar type Long but got scalar type Float for argument 首先将他翻译过来是:希望得到的是Lon

hhyys的博客 1万+

季节性注意力的时间序列预测模型 SAITS 进行数据补齐 完整代码数据

季节性注意力的时间序列预测模型 SAITS 进行数据补齐 完整代码数据

1074

使用pytorch时遇到的错误Expected object of scalar type Long but got scalar type Float for argument #2 ‘target

一.错误: Expected object of scalar type Long but got scalar type Float for argument #2 ‘target’ 二.原因及解决方法: 这句话表面上是说需要Long类型,我提供给他的是float类型,然后我把所有的变量都变成了long,发现还是不对。后来我把输入和输出x和y变成了float,因为我使用的是GCN网络,输入...

skj1995的博客 3万+

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

报错:Expected object of scalar type Float but got scalar type Long for argument #2 'target'

import torch from torch.autograd import Variable import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self): #找到Net的父类,将其转换为父类,再调用自己的 __init__() ...

weixin_43152285的博客 5万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

RuntimeError: Expected object of scalar type Long but got scalar type Float for sequence element 1 i

报错 Traceback (most recent call last): File "main.py", line 306, in <module> args_config=args_config, File "main.py", line 224, in train avg_reward, File "main.py", line 56, in train_one_epoch selected_neg_items_list, _ = sampler(bat

Iv_zzy的博客 1616

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

使用PyTorch前向运算时出现“RuntimeError: Expected object of scalar type Long but got scalar type Float for ……”

1 问题描述 今天在使用PyTorch搭建模型时,出现了一个问题: RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'weight' in call to _thnn_conv2d_forward 是在val阶段的forward函数的第一句出现的, ...

墨门 9013

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ‘target‘

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ‘target’ in call to _thnn_nll_loss_forward pytorch用**nn.CrossEntropyLoss()**计算损失的时候出错 loss = loss_fn(outputs, targets) File "D:\anaconda3\envs\py3\lib\site-pack

qq_40622955的博客 1506

Expected object of scalar type Long but got scalar type Float for argument

【代码】Expected object of scalar type Long but got scalar type Float for argument。

ResumeProject的博客 1603

Message=Expected object of scalar type Long but got scalar type Float for argument #3 ‘mat2‘ in c

在深度学习框架pytorch入门与实践的代码中 因为版本问题在 y_pred =x.mm(w)+b.expand_as(y)这句话出现报错 Message=Expected object of scalar type Long but got scalar type Float for argument #3 'mat2' in call to _th_addmm_out Source=K:\exp\PythonApplication1\PythonApplication1\PythonAp...

absxyz19931021的博客 4782

pytorch挖坑之:Expected object of scalar type Long but got scalar type Float for argument target...

目录1. 问题分析2. 总结 1. 问题分析 报错提示:需要Long类型的,但是收到了Float类型。 google了一下,都说是到相应的位置,后面加上.float()。 但是改了之后,还是不行,报了另外一个错误: 后来发现,应该是自己传的target有问题,也就是label。 查看了一下自己写的Dataset类,手动地把0变成[1, 0], 把1变成[0, 1], **其实根本不需要!!!不需...

weixin_43508499的博客 4259

解决Expected object of scalar type Long but got scalar type Float一系列问题

查阅攻略说要在targets后面加long() 结果: 出现新的问题,包括用torch.squeeze(targets)也不好使 最后发现是cross_entropy 那里出了问题,改成BCELoss后 加一句: 解决了问题

NanXian Lin的博客 688
上一篇: 记录一次tensorflow cuda out of memory
下一篇: Tensorboard could not bind to unsupported address family问题解决
coding_zhang
博客等级 码龄10年 9粉丝 39原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值