Solved by ptrblck in post #2 
              
              
                If your already have a tensor in the shape [10, 3, 5, 5], where the 5x5 tensors correspond to the mask, you can simply multiply the gradient with this tensor. There is no need to loop over each mask.