lee-zq/3DUNet-Pytorch

RuntimeError: Invalid index in scatter

Opened this issue · 3 comments

你好,我用你的网盘数据可以训练测试,但是用我自己的CT数据、分割数据,到这一步就卡住报错了:
fixd_path = r'D:\Download\3DUNet-Pytorch-master\fixed_data'
dataset = Lits_DataSet([16, 64, 64],0.5,fixd_path,mode='train') #batch size
data_loader=DataLoader(dataset=dataset,batch_size=2,num_workers=1, shuffle=True)
for batch_idx, (data, target) in enumerate(data_loader):
print("最大值:")
print(torch.max(target.long() , 0))
print(data.shape, target.shape)
target = to_one_hot_3d(target.long())

到to_one_hot_3d()函数里的scatter时报错
torch.Size([2, 1, 16, 64, 64]) torch.Size([2, 16, 64, 64])

Traceback (most recent call last):
File "D:/Download/3DUNet-Pytorch-master/dataset/dataset_lits.py", line 65, in
main()
File "D:/Download/3DUNet-Pytorch-master/dataset/dataset_lits.py", line 57, in main
target = to_one_hot_3d(target.long())
File "D:\Download\3DUNet-Pytorch-master\utils\common.py", line 28, in to_one_hot_3d
one_hot = torch.zeros(n, n_classes, s, h, w).scatter_(1, tensor.view(n, 1, s, h, w), 1)
RuntimeError: Invalid index in scatter at ..\aten\src\TH/generic/THTensorEvenMoreMath.cpp:551

这个报错大部分原因是index越界了。你也可以检查一下你的数据的shape,有些ct数据会多一个维度

您好,请问这个问题您解决了吗?

您好,请问这个问题您解决了吗?