【1】原始代码:
def __getitem__(self, index):
wt_feature = self.wt_features[index]
mt_feature = self.mt_features[index]
label = self.true_ddg[index]
# 将特征和标签转换为张量类型
wt_feature = torch.tensor(wt_feature, dtype=torch.float32)
mt_feature = torch.tensor(mt_feature, dtype=torch.float32)
label = torch.tensor(label, dtype=torch.float32)
return {"wt_feature": wt_feature, "mt_feature": mt_feature, "label": label}
在之后训练过程中,使用dataloader 在for batch 的时候出现报错:
raise keyerror (key) from err
【解释】:该报错的原因是存在超过范围的索引文章来源:https://www.toymoban.com/news/detail-579333.html
【原因】:文章来源地址https://www.toymoban.com/news/detail-579333.html
wt_feature = self.wt_features[index]
mt_feature = self.mt_features[index]
label = self.true_ddg[index]
这里输入的wt_features mt_features 是dataframe 类型,取值应该换为以下:
wt_feature = self.wt
到了这里,关于dataset 报错:raise keyerror (key) from err 、too many indexers的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!