3DUNet-Pytorch icon indicating copy to clipboard operation
3DUNet-Pytorch copied to clipboard

應用在做多類別分割,請問我該如何修改程式

Open ck6u06170 opened this issue 2 years ago • 5 comments

如題,我目前是匯入腦影像與分割結果(class=87),我目前只有修改config.py中 parser.add_argument('--n_labels', type=int, default=87,help='number of classes')

若要開始訓練則會出現以下錯誤 File "train.py", line 89, in <module> train_log = train(model, train_loader, optimizer, loss, args.n_labels, alpha) File "train.py", line 43, in train target = common.to_one_hot_3d(target,n_labels) File "/home/ma/3DUNet-Pytorch/utils/common.py", line 9, 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: index 87 is out of bounds for dimension 1 with size 87

ck6u06170 avatar Feb 22 '22 13:02 ck6u06170

解决了吗老哥

skyshowjoker avatar Mar 18 '22 03:03 skyshowjoker

後來改用pytorch提供的指令 target = torch.nn.functional.one_hot(target,n_labels) 能讀取但維度好像會跟原本輸入到model的不一樣

ck6u06170 avatar Mar 22 '22 12:03 ck6u06170

对!我也是这个错误。这一行代码没有理解,不知道咋修改。

daisysong1 avatar Apr 29 '22 08:04 daisysong1

同问

koushiyu avatar Oct 25 '22 12:10 koushiyu

87类考虑背景了吗

koushiyu avatar Oct 25 '22 14:10 koushiyu