I have a dataset which contains images and xml files with associated labels and bounding boxes. Some of the images contain have more than one label.
I have designed a dataloader to extract the annotations from xml files. Based on the dataloader, the output looks like this for 1 batch:
{'boxes': tensor([[[444., 220.,  27.,  65.],
          [468., 220.,  26.,  66.],
          [415., 224.,  20.,  33.]]]), 
'id': tensor([[1., 1., 4.]])}

From my understanding, I would need to use BCEWithLogitsLoss for a multi-label approach.
The issue I am having is how to calculate the loss when there is more than one label. When it is a single label, I use the following approach with a CrossEntropy optimiser:
    for i, data in enumerate(trainloader, 0):
        inputs, labels = data

        optimizer.zero_grad()
        outputs = net(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()

Would this approach be correct for multi-labels?