Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ck6u06170 opened this issue Feb 22, 2022 · 5 comments
Open

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

ck6u06170 opened this issue Feb 22, 2022 · 5 comments

Comments

@ck6u06170
Copy link

如題,我目前是匯入腦影像與分割結果(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

@skyshowjoker
Copy link

解决了吗老哥

@ck6u06170
Copy link
Author

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

@daisysong1
Copy link

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

@koushiyu
Copy link

同问

@koushiyu
Copy link

87类考虑背景了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants