ChangeNet icon indicating copy to clipboard operation
ChangeNet copied to clipboard

More than 2 classes

Open xuanhungho opened this issue 4 years ago • 3 comments

I want to train chang net with 3 classes, so i set num_classes to 4 (value of 4 class is 0, 1, 2, 3) and fix:

line 38 - utils_train.py to labels = sample['label'].squeeze(0).type(torch.LongTensor).to(device) but it raise error:

RuntimeErrorTraceback (most recent call last) in 1 num_epochs = 5 2 best_model, _ = utils_train.train_model(change_net, dataloaders_dict, ----> 3 criterion, optimizer, sc_plt, writer, device, num_epochs=num_epochs) 4 torch.save(best_model.state_dict(), 'best_model.pkl')

~/AFS/changenet/utils_train.py in train_model(model, dataloaders, criterion, optimizer, sc_plt, writer, device, num_epochs) 63 # backward + optimize only if in training phase 64 if phase == 'train': ---> 65 loss.backward() 66 optimizer.step() 67

/usr/local/lib/python3.6/dist-packages/torch/tensor.py in backward(self, gradient, retain_graph, create_graph) 105 products. Defaults to False. 106 """ --> 107 torch.autograd.backward(self, gradient, retain_graph, create_graph) 108 109 def register_hook(self, hook):

/usr/local/lib/python3.6/dist-packages/torch/autograd/init.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables) 91 Variable._execution_engine.run_backward( 92 tensors, grad_tensors, retain_graph, create_graph, ---> 93 allow_unreachable=True) # allow_unreachable flag 94 95

RuntimeError: cuDNN error: CUDNN_STATUS_ALLOC_FAILED

Please help me to train with 3 classes. Thanks!

xuanhungho avatar Jul 08 '20 01:07 xuanhungho

would it be possible to know if you managed to run the model with 2 classes?

JeanChillet avatar Jan 05 '21 16:01 JeanChillet

Yes, I have successfully run the model with multiple classes, please pay attention to the loss function

xuanhungho avatar Jan 06 '21 16:01 xuanhungho

Hello sir, Thank you very much for your reply. I am actually at an earlier stage than this as I have some issues iterating through the dataloader. Indeed it looks like working with dictionaries causes some problems. When I change it to a list I have an other error saying that I am the "test image" is not found. Do you have any advice or example that could help me with this? Thank you very much for your time and your help.

Kind regards,

Jean


De : Hồ Xuân Hùng [email protected] Envoyé : 7 janvier 2021 06:52 À : leonardoaraujosantos/ChangeNet [email protected] Cc : Jean Chillet [email protected]; Comment [email protected] Objet : Re: [leonardoaraujosantos/ChangeNet] More than 2 classes (#10)

Yes, I have successfully run the model with multiple classes, please pay attention to the loss function

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/leonardoaraujosantos/ChangeNet/issues/10#issuecomment-755422579, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKST7MEKYT5NEOTYI7Z2EVDSYSIMHANCNFSM4OT7UHRQ.

JeanChillet avatar Jan 06 '21 17:01 JeanChillet