PyTorch 特征标签化函数:LabelFeature
这个函数的作用是给输入的特征和标签进行打标签操作。它接受两个参数,分别是特征和标签。它首先将标签进行扩充,使得与特征的长度相同,然后将标签转换为 torch.tensor 类型,并将特征和标签作为结果返回。
def LabelFeature(feature, label):
labels = [label] * len(feature)
labels = torch.tensor(labels)
return feature, labels
原文地址: https://www.cveoy.top/t/topic/czV9 著作权归作者所有。请勿转载和采集!