Thank you for your advice.
Based on your suggestion, I make a change to check it.
Since sigmoid_x.log() only exists in the def of weighted_BCE(), I # the temp_label like this:
        for i in range(L):
            temp = weighted_BCE(sigmoid_x = inputs[..., i], targets = targets[..., i])
#            temp_label = (1 - (targets[..., i] * inputs[..., i] + (1 - targets[..., i]) * (1 - inputs[...,i]))) ** gamma * temp
#            loss += temp_label
            loss += temp

and all the rest remains the same.
Now the loss will only calculate weighted_BCE without calculating temp_label, and until now the network works well(around 7 epochs, I set 30 epochs so I will tell you the result later).
So I think sigmoid_x.log() may not be the reason, as the input is the output of nn.sigmoid().