Hi @ptrblck,
Summing the masks would not be an appropriate approach to this problem. Each mask represents a connected component (of arbitrary shape) in the image. I use them for a custom max pooling operation. So for each mask, all pixels of that CC are set to their maximum value.
The operation does not have to be sequential, but I could not think of a better way than the for loop, so any non-sequential approaches are especially welcome. Here is an example and I can post its whole code if needed but I’m basically stuck at the for loop mentioned in the 1st post.
>>> inp
tensor([[[[11., 11., 10., 12.],
          [10., 11., 11., 10.],
          [11., 12., 12., 12.],
          [10., 12., 11., 10.]]]], requires_grad=True)

>>> CCs
tensor([[0., 0., 0., 1.],
        [2., 2., 2., 2.],
        [2., 2., 2., 2.],
        [2., 2., 2., 2.]])

>>> masks
tensor([[[[[ True,  True,  True, False],
           [False, False, False, False],
           [False, False, False, False],
           [False, False, False, False]]]],

        [[[[False, False, False,  True],
           [False, False, False, False],
           [False, False, False, False],
           [False, False, False, False]]]],

        [[[[False, False, False, False],
           [ True,  True,  True,  True],
           [ True,  True,  True,  True],
           [ True,  True,  True,  True]]]]])

>>> output
tensor([[[[11., 11., 11., 12.],
          [12., 12., 12., 12.],
          [12., 12., 12., 12.],
          [12., 12., 12., 12.]]]])