Different losses for different images in the same batch

I would like to use different loss functions for different images which are in the same batch. For example, lets say my batch size is 8, and for the images 1,2 and 8 I am going to use Loss 1, and for the rest of the images I am going to use Loss 2. Assume that both are cross-entropy losses. Is there any way to easily implement it using PyTorch? In other words I have to select which loss should be used for each of the images in a particular batch.

You could slice the output and target in order to pass each chunk to the desired loss function.
Afterwards you could sum or average these losses and call backward on the reduced loss.