0

Can we apply both MSELoss and CrossEntropyLoss in a single network to predict both classification and regression in Deep Learning? Suppose that we have 4 points(regression) and 5 classes(classification) to predict and we use both those loss function. I have built a simple network, but I did not get a good result. I applied loss function like this:

criterion1 = nn.MSELoss()
criterion2 = nn.CrossEntropyLoss()

loss1 = criterion1(logits[:,:4], y)# regression            
loss2 = criterion2(logits[:,4:].softmax(dim=1), cl) #classification
             
loss = .1*loss1 + loss2
loss2.backward()

optim.step()

Also I just applied only the CrossEntropyLoss to network but I got good result. So, should we use separate models to predict targets?

Mahdi Amrollahi
  • 263
  • 2
  • 10
  • 1
    Yes, quite trivially, but you have to decide how to combine them. Do you have some sense of how to do that? For instance, would it make sense to add them together and minimize that sum? – Dave Nov 12 '22 at 06:10
  • I have no idea about that. I just tried the summation! – Mahdi Amrollahi Nov 12 '22 at 06:40

0 Answers0