My tatget and output are of shape [B, C, H, W].  Positive weights is of shape [C].
target = torch.ones([1, 2, 5, 5], dtype=torch.float32)
output = torch.randn(1, 2, 5, 5, requires_grad=True)
positive_weights = torch.FloatTensor([2, 2])
criterion = torch.nn.BCEWithLogitsLoss(pos_weight=positive_weights)
loss = criterion(output, target)
loss.backward()

The error is:
RuntimeError: The size of tensor a (2) must match the size of tensor b (5) at non-singleton dimension 3

How to fix this?