BCEWithLogitsLoss autoencoders

Hello all,

I have an auto-encoder trained with BCEWithLogitsLoss(). Say the output dimension is 10, and I feed a data batch of size 20 into the network during testing. Say, y_hat is my output vector (i.e., reconstruction of the input of dimension 10), and say y is my actual input data:

criterion = nn.BCEWithLogitsLoss()
e = criterion(y_hat, data)

Unfortunately, e has is just a scalar! What I need is individual error vectors. In particular, I want e to be NOT aggregated, and have the dimensionality of (batchsize, data_dimension)= (20,10). Then I can average my ‘e’ across the second dimension and end up with an average error vector of size 20!

This way for 20 input data, I will have 20 individual error values and I can compute my performance (e.g., AUC). Any ideas how I can do this?

Thanks a lot

P.S.
If it was just BCE() error function, I could have just written the math and computed it manually, but BCEWithLogitsLoss() is tricky to code from scratch (I think!)

If you don’t want to compute the loss average you can pass reduction='none' to nn.BCEWithLogitsLoss.

1 Like

Thank you so much for the fast response. You guys are amazing!