异常:IndexError: tensors used as indices must be long, byte or bool tensors
异常:IndexError: tensors used as indices must be long, byte or bool tensors
详细异常
Traceback (most recent call last):File "D:/PythonCode/pytorch131/UltraGCN-main/main.py", line 624, in <module>train(ultragcn, optimizer, train_loader, test_loader, mask, test_ground_truth_list, interacted_items, params)File "D:/PythonCode/pytorch131/UltraGCN-main/main.py", line 410, in trainloss = model(users, pos_items, neg_items)File "C:\anaconda3\envs\pytorch131\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__result = self.forward(*input, **kwargs)File "D:/PythonCode/pytorch131/UltraGCN-main/main.py", line 359, in forwardomega_weight = self.get_omegas(users, pos_items, neg_items)File "D:/PythonCode/pytorch131/UltraGCN-main/main.py", line 300, in get_omegaspos_weight = self.constraint_mat[users * self.item_num + pos_items].to(device)
IndexError: tensors used as indices must be long, byte or bool tensors
# 错误语句
pos_weight = self.constraint_mat[users * self.item_num + pos_items].to(device)
这个异常不是一个单一异常,后面所有用的 user, pos_items, neg_items 等等语句都可能报这个异常。
所以要找到根源的 user, pos_items, neg_items
变量。
说明,每个代码的异常变量都不一样,要测试好是那个变量的问题。可以通过逐一改变变量的类型(
.long()
)测试。
我的根源语句是
users = users.to(device)
pos_items = pos_items.to(device)
neg_items = neg_items.to(device)
改正后
users = users.long().to(device)
pos_items = pos_items.long().to(device)
neg_items = neg_items.long().to(device)
看的其他的解答,pytorch框架 下long()
也可以换为.type(torch.long)
异常:IndexError: tensors used as indices must be long, byte or bool tensors相关推荐
- IndexError: tensors used as indices must be long, byte or bool tensors
下面的程序会报错IndexError: tensors used as indices must be long, byte or bool tensors mask = torch.Tensor([ ...
- tensors used as indices must be long or byte tensors
tensors used as indices must be long or byte tensors import torch import numpy as np a=torch.zeros(( ...
- 成功解决IndexError: arrays used as indices must be of integer (or boolean) type
成功解决IndexError: arrays used as indices must be of integer (or boolean) type 目录 解决问题 解决思路 解决方法 解决问题 I ...
- 【pyradiomics】bugFix:GLCM特征时:IndexError: arrays used as indices must be of integer (or boolean) type
GLCM特征时出现bug:IndexError: arrays used as indices must be of integer (or boolean) type 解决方法:https://gi ...
- 【Sketch2Pose项目环境搭建】win10+Anoconda+VScode
最近我尝试在windows上运行Sketch2Pose这个项目,但前前后后花了很久,疯狂踩坑,嗯,很崩溃,遇到很多问题.于是写这篇博客,结合原仓库Readme内容,记录一下项目环境搭建的过程. 搭建环 ...
- 三元组损失tripletloss
雷郭出品 先验知识 1.Triplet loss 2. Hard Triplets选择 先验知识 题外话(来自网络): (最近,learning to rank 的思想逐渐被应用到很多领域,比如goo ...
- python中slice 和 indices使用
一般来说,内置的slice()函数会创建一个切片对象,可以用在任何允许进行切片操作的地方. 下面是slice的简介: # slice 两种用法 class slice(stop)class slice ...
- python进阶八_警告和异常
心情有点纠结,怎么说呢,倒不是因为其他学习上的事情,反而是因为生活上狗血的剧情逼着人偏离,渐行渐远,人跟人之间有误会也是正常的,可能是因为交流不够,彼此不够了解吧,希望能尽快度过这一段纠结的日子,简单 ...
- Python基础(九)--异常
Python基础(九)--异常 1 异常相关概念 1.1 什么是异常 异常是程序运行过程中产生的一种事件,该事件会打乱程序的正常流程.可以说,异常就是一种意外,指程序没有按照正常或期望的方式执行. 当 ...
最新文章
- Redis在Windows上编译
- gin 项目结构_Gin框架 - 项目目录
- python 安装包时出现红字_Python安装(Windows 7 8 10)
- OC__part11.2
- Runtime error 216 at xxx 故障解决一例
- 数据科学 IPython 笔记本 9.9 花式索引
- 基于文本和语音的双模态情感分析
- React Native Fetch封装那点事...
- gulp自己主动化任务脚本在HybridApp开发中的使用
- 自由缩放属性-resize(禁止textarea的自由缩放尺寸功能)
- 服务器端提交form
- 【Python】Json序列化和反序列化模块dumps、loads、dump、load函数介绍
- 鲁棒控制(Ⅰ)—LMI处理方法
- 阿里巴巴矢量字体库更改设置
- Git-删除文件后找回
- Shake Shack上海第7家门店开业
- android获取短信中心号
- 搜狐畅言评论系统使用
- 转速/线速度/角速度计算FC
- Linux环境下Font font = new Font(黑体, Font.BOLD, 18)[BufferedImage~Graphics~drawString]中文乱码