報錯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,這樣就可以啦…這麼個錯誤弄了一上午,崩潰…希望能幫到小可愛們~
相關文章
- Pytorch——張量 TensorsPyTorch
- 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
- Python:Python3錯誤提示TypeError: slice indices must be integers or None or have an __index__ method解決辦法PythonErrorNoneIndex
- TypeError: The ‘compilation‘ argument must be an instance of Compilation 報錯Error
- 【基礎語法】short、int、long轉為byte
- object dict cannot be used in await expression報錯解釋ObjectAIExpress
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- [STF 求助帖] stf-app 模組報錯 Key must be a bufferAPP
- [專案踩坑] py executemany 的使用報錯:Not all parameters were used in the SQLSQL
- [20210113]SP2-0232 Input too long. Must be less than 241 characters.txt
- git拉取程式碼報錯filename too long unable to create fileGit
- thinkphp升級後報錯Declaration of thinkappUrl::build() must be compatible with think outeUrl::build():PHPAPPUI
- python 報錯:raise IllegalCharacterError(f"{value} cannot be used in worksheets.") openpyxl.utils.exceptions.IllegalCharacterErrorPythonAIErrorException
- 執行遷移檔案報錯 1071 Specified key was too long.
- 【Redis】錯誤:failed: Hostname must not be empty or nullRedisAINull
- Android之Retrofit報錯Form-encoded method must contain at least one @Field.AndroidORMAIAST
- Input報錯“Form elements must have labels: Element has no title attribute Element has no placeholde”ORM
- Python3.7使用pip install xxxx報錯:UnicodeDecodeError: 'gbk' codec can't decode bytePythonUnicodeError
- idea在使用git clone 時出現Filename too long的報錯資訊IdeaGit
- Elasticsearch 6 建立索引報錯 invalid_index_name_exception Invalid index name [testDemo], must be lowercaseElasticsearch索引IndexException
- vue專案報錯[Vue warn]: Property “visible“ must be accessed with “$data.visible“ because properties startVue
- npm報錯 TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string.Received undefineNPMError
- Property visible must be accessed with $ or _ are not proxied in the Vue instance to prevent錯誤Vue
- bool QMetaMethod::invoke
- [報錯:字元太長] SQLSTATE [42000]: Syntax error or access violation: 1071 Specified key was t oo long;字元SQLError
- PIP3安裝報錯nicodeDecodeError: 'ascii' codec can't decode byte 0xc3ErrorASCII
- Elasticsearch bool query小結Elasticsearch
- 直接用 appium 可以連線真機,用 pycharm 執行指令碼時報錯 “'platformVersion' must be of type string”APPPyCharm指令碼Platform
- webstorm除錯(一)提示css未使用的選擇器Selector is never usedWebORM除錯CSS
- pytorch執行錯誤:RuntimeError: a leaf Variable that requires grad is being used in an in-place operationPyTorchErrorUI
- 新年新歲,好運 long long
- long long的加法溢位情況
- Solidity String轉byte32 byte轉StringSolid
- ORA-01440: column to be modified must be empty (修改列型別時報錯:要修改的列必須為空)型別
- Oracle Least Recently Used ChainsOracleASTAI
- python---argparse 解析 bool 值Python