I've been struggling to understand this code despite having searched google for codes that look like this (or parts of the code) for some while now and was wondering if someone could help me understand this.
(img.sum(dim=1)!=0).float()[:, None, :, :]
(for reference, the original code is from line 561 of this file.)
From what I've understood so far,
- It seems like img.sum(dim=1) wants to sum up all the values of the img along their columns (so sum up horizontally across columns).
- I'm not sure what exactly the !=0 part is doing, but I assume it's going to give me a boolean value of img.sum(dim=1), with 1 or 0 for each row depending on the sum's value.
- And the values are converted to float through .float()
- This is where I'm getting most confused. I had thought that (img.sum(dim=1)!=0) gave me just four rows, with one value in each row. Then why would be have ":", which I understand to select everything? (Are my interpretations 1-3 wrong?) Also, what exactly is the None doing?