Thank you for your answer but maybe I was not clear with the question. You dont use the number_of_features variable which corresponds to the number of binary masks in the first layer. In the network, we want to generate M pieces of binary masks ((1,M,128,128)) and then the next layer is the sum of each images thus we will get an (1,M) size tensor. And what really confuses me is how to change the binary masks during the training because if they are only 0 and 1 than how can we define the derivative of these masks? At least for my code they wont change but this is the main point of this task to optimize the masks.
I hope now my question is more clear