I think I understood your answer now and why using nn.BCEWithLogitsLoss() together with Sigmoid is a bad idea. Thanks a lot!
So I’d like to do the second proposal. But what I don’t understand is, why the model outputs 0 or 1 and not values between 0 and 1.
Output of the model (i.e. pred) looks like this:
tensor([[1.],
        [0.],
        [0.],
        [0.],
        ...
        [0.],
        [1.],
        [0.],
        [0.],
        [1.]], grad_fn=<SigmoidBackward>)

I would like to have an output as in keras:
[4.5889354e-01],
       [1.0000000e+00],
       [9.9999785e-01],
       ...
       [8.9359963e-01],
       [1.0000000e+00],
       [2.6206519e-05],
       [1.0000000e+00],
       [1.0000000e+00]], dtype=float32)>