Hello all!
I am working on a room-image classifier, which for a given image predicts: (1) what type of room it is (e.g. bedroom); (2) what style does the room have (e.g. modern); (3) does it look high or low budget.
I want to add a category for an “empty room” in the room types, but empty rooms should not have a style or budget associated with them. Therefore, in those cases where the room label is “empty”, I want to ignore the Cross Entropy losses associated with the style and budget. However, I cannot figure out how to do this for the entire batch at once.
For clarity’s sake, the losses (ignoring the condition) are computed as follows (based on one-hot encoding):
loss_r = nn.CrossEntropyLoss()(r_p, r_t)
loss_s = nn.CrossEntropyLoss()(s_p, s_t)
loss_b = nn.CrossEntropyLoss()(b_p, b_t)
where r_p
, s_p
, and b_p
are the predictions (in logits), and r_t
, s_t
, and b_t
are the targets.
Cheers!