報錯indexerror: tensors used as indices must be long, byte or bool tensors
報錯
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(batch_data, adj_matrix, edge_matrix)
File "/home/zzy/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/home/zzy/KG-Policy/kgpolicy/modules/sampler/kgpolicy.py", line 91, in forward
one_hop, one_hop_logits = self.kg_step(pos, users, adj_matrix, step=1)
File "/home/zzy/KG-Policy/kgpolicy/modules/sampler/kgpolicy.py", line 139, in kg_step
i_e = gcn_embedding[one_hop]
IndexError: tensors used as indices must be long, byte or bool tensors
定位到kgpolicy檔案的第139行
one_hop = adj_matrix[pos]
i_e = gcn_embedding[one_hop]
感覺索引indices是one_hop ,檢查下one_hop:
print(one_hop)
結果為:
tensor([[ 1295., 6801., 6590., ..., 43463., 63427., 23697.],
[ 2940., 23298., 4720., ..., 54026., 45077., 68521.],
[ 136., 137., 1033., ..., 47605., 59133., 51274.],
...,
[ 1629., 6126., 118., ..., 56004., 23626., 41774.],
[12689., 6415., 21290., ..., 28091., 24405., 37709.],
[ 739., 818., 1202., ..., 54062., 29978., 25789.]])
因為預設的是float型別,所以不對,就直接型別轉換為long就可以了.
關於究竟轉化為哪種型別,參考連結:
https://blog.csdn.net/junqing_wu/article/details/99692296
https://blog.csdn.net/jacke121/article/details/82703640
https://blog.csdn.net/weixin_38314865/article/details/105949825
one_hop = adj_matrix[pos].type(torch.long)#已修改
i_e = gcn_embedding[one_hop]
ok,這樣就可以啦…這麼個錯誤弄了一上午,崩潰…希望能幫到小可愛們~
相關文章
- DEEP LEARNING WITH PYTORCH: A 60 MINUTE BLITZ | TENSORSPyTorch
- python報錯:TypeError: slice indices must be integers or None or have an __index__ methodPythonErrorNoneIndex
- python爬蟲 -IndexError: list index out of range報錯Python爬蟲IndexError
- mongodb報錯:the limit must be specified as a number。MongoDBMIT
- Python:Python3錯誤提示TypeError: slice indices must be integers or None or have an __index__ method解決辦法PythonErrorNoneIndex
- object dict cannot be used in await expression報錯解釋ObjectAIExpress
- 【基礎語法】short、int、long轉為byte
- TypeError: The ‘compilation‘ argument must be an instance of Compilation 報錯Error
- 報錯資訊 The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements 的原因及解決辦法JSIDEForward
- [STF 求助帖] stf-app 模組報錯 Key must be a bufferAPP
- informix停資料庫是報錯:Must be a DBSA to run this programORM資料庫
- CocoaPods報錯:The dependency `AFNetworking ` is not used in any concrete target
- git拉取程式碼報錯filename too long unable to create fileGit
- Oracle PL/SQL INDICESOracleSQL
- [專案踩坑] py executemany 的使用報錯:Not all parameters were used in the SQLSQL
- python 報錯:raise IllegalCharacterError(f"{value} cannot be used in worksheets.") openpyxl.utils.exceptions.IllegalCharacterErrorPythonAIErrorException
- 【Redis】錯誤:failed: Hostname must not be empty or nullRedisAINull
- thinkphp升級後報錯Declaration of thinkappUrl::build() must be compatible with think outeUrl::build():PHPAPPUI
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- pip install 報錯UnicodeDecodeError: 'ascii' codec can't decode byteUnicodeErrorASCII
- 執行遷移檔案報錯 1071 Specified key was too long.
- idea在使用git clone 時出現Filename too long的報錯資訊IdeaGit
- bool QMetaMethod::invoke
- Android之Retrofit報錯Form-encoded method must contain at least one @Field.AndroidORMAIAST
- Identify If A Disk/Part Is Still Used By ASM,Used by ASM Or Used by ASM_603210.1IDEASM
- Xtrabackup恢復時報錯'Error: datadir must be specified'Error
- npm報錯 TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string.Received undefineNPMError
- json解析boolJSON
- Elasticsearch 6 建立索引報錯 invalid_index_name_exception Invalid index name [testDemo], must be lowercaseElasticsearch索引IndexException
- 除錯記錄:The public type must be defined in its own file除錯
- Laravel 5.4 常見錯誤:Specified key was too longLaravel
- Elasticsearch bool query小結Elasticsearch
- vue專案報錯[Vue warn]: Property “visible“ must be accessed with “$data.visible“ because properties startVue
- django模板報錯:Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either defineDjango
- 安裝Oracle報Checking os version: must be redhat-3OracleRedhat
- 工程中報錯或者警告(持續更新)(例如:does not contain bitcode. You must rebuild it with bitcode enabled )AIRebuild
- Script form where usedORM
- Signals used by the JVMJVM