cpu版本对应python3.9应该安装什么版本的torch_scatter
时间: 2023-11-21 10:05:50 浏览: 60
如果您的CPU支持AVX2指令集,则可以安装torch_scatter 2.0.8版本,命令如下:
```
pip install torch_scatter==2.0.8 -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html
```
如果您的CPU不支持AVX2指令集,则需要安装旧版本的torch_scatter,如1.4.0版本,命令如下:
```
pip install torch_scatter==1.4.0 -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html
```
请注意,以上命令假定您已经安装了PyTorch 1.9.0和对应的torchvision版本。如果您的环境不同,请根据实际情况进行相应的修改。
相关问题
Traceback (most recent call last): File "/home/bder73002/hpy/ConvNextV2_Demo/train+.py", line 280, in <module> train_loss, train_acc = train(model_ft, DEVICE, train_loader, optimizer, epoch,model_ema) File "/home/bder73002/hpy/ConvNextV2_Demo/train+.py", line 46, in train loss = torch.nan_to_num(criterion_train(output, targets)) # 计算loss File "/home/bder73002/anaconda3/envs/python3.9.2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/home/bder73002/hpy/ConvNextV2_Demo/models/utils.py", line 182, in forward ldam_loss = self.ldam_loss(x, target) File "/home/bder73002/anaconda3/envs/python3.9.2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/home/bder73002/hpy/ConvNextV2_Demo/models/utils.py", line 148, in forward index.scatter_(1, target.data.view(-1, 1), 1) IndexError: scatter_(): Expected dtype int64 for index.
这个错误提示是在使用 PyTorch 进行训练时出现的。出现这个错误的原因是在执行 index.scatter_() 操作时,index 的数据类型应该是 int64,但实际上它的数据类型不是 int64。
你可以检查一下代码,看一下 index 的数据类型是否正确,如果不正确,可以使用 index = index.long() 将其转换为 int64 数据类型。另外,还需要确保 target 的数据类型也是 int64。
希望这能解决你的问题!
代码如下:class LDAMLoss(nn.Module): def __init__(self, cls_num_list, max_m=0.5, weight=None, s=30): super(LDAMLoss, self).__init__() m_list = 1.0 / np.sqrt(np.sqrt(cls_num_list)) m_list = m_list * (max_m / np.max(m_list)) m_list = torch.cuda.FloatTensor(m_list) self.m_list = m_list assert s > 0 self.s = s self.weight = weight def forward(self, x, target): index = torch.zeros_like(x, dtype=torch.uint8) index.scatter_(1, target.data.view(-1, 1), 1) index_float = index.type(torch.cuda.FloatTensor) batch_m = torch.matmul(self.m_list[None, :], index_float.transpose(0,1)) batch_m = batch_m.view((-1, 1)) x_m = x - batch_m output = torch.where(index, x_m, x) return F.cross_entropy(self.s*output, target, weight=self.weight) 报错:Traceback (most recent call last): File "/home/bder73002/hpy/ConvNextV2_Demo/train+.py", line 280, in <module> train_loss, train_acc = train(model_ft, DEVICE, train_loader, optimizer, epoch,model_ema) File "/home/bder73002/hpy/ConvNextV2_Demo/train+.py", line 46, in train loss = torch.nan_to_num(criterion_train(output, targets)) # 计算loss File "/home/bder73002/anaconda3/envs/python3.9.2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/home/bder73002/hpy/ConvNextV2_Demo/models/utils.py", line 182, in forward ldam_loss = self.ldam_loss(x, target) File "/home/bder73002/anaconda3/envs/python3.9.2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/home/bder73002/hpy/ConvNextV2_Demo/models/utils.py", line 148, in forward index.scatter_(1, target.data.view(-1, 1), 1) IndexError: scatter_(): Expected dtype int64 for index.
根据报错信息,你需要将 index 的数据类型转换为 int64。可以在 index 定义时指定它的数据类型为 int64:
```
index = torch.zeros_like(x, dtype=torch.int64)
```
或者可以在 scatter_() 操作前,将 index 的数据类型转换为 int64:
```
index = index.type(torch.int64)
index.scatter_(1, target.data.view(-1, 1), 1)
```
这样应该就能解决这个错误了。