Hi Giuseppe!



 Giuseppe:

                    input = nn.Sigmoid(rec)
                    lossAE = nn.BCELoss(input, Target)

    input = nn.Sigmoid(rec)
TypeError: __init__() takes 1 positional argument but 2 were given




You are calling the constructor for Sigmoid incorrectly, namely with
an explicit argument.  (There is also the hidden self argument.  That
is why the error message complains about two arguments.)
In more detail, torch.nn.Sigmoid is a class, while torch.sigmoid()
is a function (as is the deprecated torch.nn.functional.sigmoid()).
So you have to construct an instance of Sigmoid before you can call
it as a so-called function object.  (You can construct it on the fly, if you
like.)
Thus:
activation = nn.Sigmoid()
...
input = activation (rec)

# or

input = nn.Sigmoid() (rec)

# or

input = torch.sigmoid (rec)

(All three do the same thing.)


Furthermore i would like to use  BCEWithLogitsLoss, what should I pass as pos_weight?


Class weights in loss functions are typically used to account for
unbalanced datasets where certain classes occur significantly more
frequently than others.
For a binary classification problem – including a multi-label, multi-class
problem, which is basically nClass binary problems being processed
“in parallel” – you have two classes, “negative” and “positive.”
Common practice is to use pos_weight = n_negative / n_positive,
passed into the constructor of BCEWithLogitsLoss.  (In the multi-label
case, you would pass in a vector of nClass pos_weight values, one
for each of your classes.)
(For whatever reason, BCELoss doesn’t take a pos_weight
constructor argument.)
As a side note, you are correct to prefer BCEWithLogitsLoss,
without the explicit Sigmoid, over BCELoss.
Best.
K. Frank