Hi there,
I am performing an anomaly detection problem on images and wish to binary classify each column in an image. Each input image is a standard 500 pixels wide and therefore my output layer will contain 500 neurons with a sigmoid activation. I wish to use PyTorch but am having a problem deciding on a loss function. I am wondering if the following can be cleared up for me:

Is BCELoss or BCEWithLogitsLoss (preferable) suitable for this problem?
My dataset is also unbalanced and I wish to assign class weighting to the loss function. For example, if the ratio of positive to negative class is 1:3 how would I assign a class weighting here? I am aware BCEWithLogitsLoss has 2 parameters ‘weight’ and ‘pos_weight’. ‘pos_weight’ seems to be the parameter which assigns weighting to the positive class. What I would like to do is assign the positive class a value of 3. However, documentation states ‘pos_weight’ requires ‘length equal to the number of classes’ which would require pos_weight=[3]*500 in my case. Would this be sufficient in assigning class weighting for my problem?

Thank you in advance for any help.