RuntimeError: Expected object of type torch.cuda.LongTensor but found type torch.cuda.IntTensor 2022-03-28 17:42 54阅读 0赞 ## 问题: ## anchor_label = np.array(self.id_dict[int(anchor_id)]) identity_loss = criterion_identity(predicted_id_rgb, anchor_label) + criterion_identity(predicted_id_ir, anchor_label) **RuntimeError:** Expected object of type torch.cuda.LongTensor but found type torch.cuda.IntTensor for argument \#2 'target' ## 释义: ## 第二个参数 anchor\_label 类型为 IntTensor,不符合要求的 **LongTensor** ## 原因: ## python2 中取消了long 型,python3 统一用 int 型代替 python3中int 支持位数等于 python2 中long型位数 ## 测试: ## import numpy as np x = np.float32(1.0) >>> x 1.0 y = np.int_([1,2,4]) >>> y array([1, 2, 4]) # dtype 属性确定数组元素的类型,dtype参数说明,详见下面链接 # https://www.jianshu.com/p/6ca8729dd102 z1 =np.array(12752649778202, dtype=np.int_) >>> z1 OverflowError: Python int too large to convert to C long z2 =np.array(12752649778202, dtype=np.int32) >>> z2 OverflowError: Python int too large to convert to C long z3 =np.array(12752649778202, dtype=np.int64) >>> z3 OverflowError: Python int too large to convert to C long z4 =np.array(12752649778202, dtype=np.int) >>> z4 OverflowError: Python int too large to convert to C long # 成功找到解决办法 z =np.array(12752649778202, dtype=np.intp) >>> z 12752649778202 ## 解决办法: ## 1. ***dtype 设为 np.intp,可使 python2中 long 类型 等价到 python3 中使用*** 2. ***采用C/C++语言的强制转化,int(long型数值), 可能将超过int位数的字符截断,故建议使用dtype 方式*** anchor_label = np.array(self.id_dict[int(anchor_id)],dtype=np.intp) # python3 或者 anchor_label = np.array(int(self.id_dict[int(anchor_id)])) # C/C++ 强制转化 文章版权声明:注明蒲公英云原创文章,转载或复制请以超链接形式并注明出处。
相关 Expected receiver of type com.xx.xxxActivity, but got android.view.ContextThemeWrapper java.lang.IllegalArgumentException: Expected receiver of type com.xx.xxxActivity, but go 淡淡的烟草味﹌/ 2021年11月23日 08:10/ 0 赞/ 324 阅读
相关 Expected indentation of 12 spaces but found 11. 修改IDEA或webstorm配置,File => Setting => Editor => Code Style => HTML,找到 add Do not indent c 喜欢ヅ旅行/ 2022年02月18日 21:19/ 0 赞/ 397 阅读
相关 Expected indentation of 0 spaces but found 2 在webstrom中写代码以后使用ctrl+alt+l规范了代码 但是还是报Expected indentation of 0 spaces but found 2 这 ﹏ヽ暗。殇╰゛Y/ 2022年03月15日 22:22/ 0 赞/ 63 阅读
相关 Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument 从报错信息来:需要的输入参数类型为torch.FloatTensor,但实际上给定是torch.cuda.FloatTensor 解决方法 首先可以肯定的是由于张量类型不 旧城等待,/ 2022年03月17日 19:59/ 0 赞/ 59 阅读
相关 RuntimeError: Expected object of type torch.cuda.LongTensor but found type torch.cuda.IntTensor 问题: anchor_label = np.array(self.id_dict[int(anchor_id)]) identity_loss 矫情吗;*/ 2022年03月28日 17:42/ 0 赞/ 55 阅读
相关 【解决方案】Expected object of type torch.FloatTensor but found type torch.DoubleTensor 简述 在网上找了半天没有得到解答。 但是,在pycharm输入`.`之后,发现有一个函数很有意思,然后得到了解决 解决方案 假如报错的语句是 `mod Dear 丶/ 2022年04月17日 14:29/ 0 赞/ 72 阅读
相关 RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for ar 运行如下程序: import numpy as np import torch from torch import nn from torch 一时失言乱红尘/ 2022年05月08日 10:40/ 0 赞/ 46 阅读
相关 is expected to be of type but was actually of type 'com.sun.proxy.$Proxy70' spring boot项目,启动报这个异常 原因是:我通过@EnableTransactionManagement 启动了事务,但是没有开启cglib的动态代理。 appl 布满荆棘的人生/ 2022年06月04日 10:12/ 0 赞/ 43 阅读
相关 DefaultSerializer requires a Serializable payload but received an object of type ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ub 拼搏现实的明天。/ 2022年09月02日 23:57/ 0 赞/ 33 阅读
相关 RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 ‘target‘ 一般有三点错误 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") 1、 待我称王封你为后i/ 2022年12月08日 23:46/ 0 赞/ 29 阅读
还没有评论,来说两句吧...