The error indicates that there is an invalid literal for the int() function in the read_labels() method. The error occurs because the line in label.csv contains multiple labels separated by commas, instead of a single integer label.

To fix this issue, you need to modify the read_labels() method to split the line by commas and convert each label to an integer. Here's the updated code:

def read_labels(self):
    label_path = self.root + '/label.csv'
    labels = torch.tensor([])
    with open(label_path, 'r') as f:
        for line in f.readlines():
            label_list = line.strip().split(',')
            label = [int(x) for x in label_list]
            labels = torch.cat((labels, torch.tensor(label)))
    return labels.long()

After making this change, the code should be able to read the labels correctly.

import torch import torchnnfunctional as F from torch_geometricdata import Data Dataset from torch_geometricnn import GCNConv class MyDatasetDataset def __init__self root selfroot = root

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

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