The error 'KeyError: tensor([[ True, True, True, ..., False, False, False], [ True, True, True, ..., False, False, False], [ True, True, True, ..., False, False, False], ..., [ True, True, True, ..., False, False, False], [ True, True, True, ..., False, False, False], [ True, True, True, ..., False, False, False]])' occurs because you are trying to index the 'data' object using a boolean mask. However, the 'Data' object does not support boolean indexing by default.

To fix this error, you can manually create a new 'Data' object using the selected indices from the boolean mask. Here's an example of how you can do it:

# 创建图结构
edge_index = torch.tensor(edges, dtype=torch.long).t().contiguous()
data = Data(x=x, edge_index=edge_index)

# 将数据划分为训练集和验证集
train_data = Data(x=data.x[mask_train], edge_index=data.edge_index)
val_data = Data(x=data.x[mask_val], edge_index=data.edge_index)

In this example, we create a new 'Data' object for the training and validation sets using the selected indices from the boolean masks 'mask_train' and 'mask_val'.

解决PyTorch Geometric中'KeyError: tensor([...])' 错误

原文地址: https://www.cveoy.top/t/topic/pfTX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录