What is the exact error you are getting in this case?
You might want to check that the datatype of labels is a torch tensor as expected.
The documentation shows a simple of example of input being passed to the loss function: BCELoss — PyTorch 1.9.0 documentation 2
although in your case you will likely also have a batch dimension.