这个错误是因为scatter_()函数的第一个参数需要是int64类型的index tensor,但是当前传入的y.unsqueeze(1)是float32类型的tensor。要解决这个问题,你可以将y.unsqueeze(1)的数据类型转换为int64,代码如下:

one_hot_labels = torch.zeros((len(y), self.config.n_way)).cuda(self.config.gpu).scatter_(1, y.unsqueeze(1).long(), 1)

通过使用.long()将数据类型转换为int64,就可以解决这个问题。

请改正在 y = torchfrom_numpynprepeatrangeselfconfign_way selfconfign_query_traincudaselfconfiggpu one_hot_labels = torchzerosleny selfconfign_waycudaselfconfiggpuscatter_1 yunsqueeze1 1出现如下的报错:

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

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