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.\n\nTo 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:\n\npython\ndef read_labels(self):\n label_path = self.root + '/label.csv'\n labels = torch.tensor([])\n with open(label_path, 'r') as f:\n for line in f.readlines():\n label_list = line.strip().split(',')\n label = [int(x) for x in label_list]\n labels = torch.cat((labels, torch.tensor(label)))\n return labels.long()\n\n\nAfter making this change, the code should be able to read the labels correctly.

解决“ValueError: invalid literal for int() with base 10”错误:使用PyTorch GCN进行图神经网络训练

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

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