Assuming you have a N * M tensor, you can use the following code as a sanity check
assert(all([val >= 0 and val <= 1 for row in x.cpu().detach().numpy() for val in row]))
If this assertion fail, then you just need to normalize the output by adding a Sigmoid to x to resolve the problem. Otherwise there’s some other problems