I’m not exactly sure, how the code is supposed to work.
Currently you have some issues in your code:


self.main is never used
you recreate layers = [] inside the loop, and overwrite self.all_layers with the last two layers
the returned output list will throw the mentioned error, since the criterion expects tensors not lists
even if you try to torch.stack the output (which would be the usual workflow), you will most likely encounter errors, since you are using a mask to index zn, which will create variable sized outputs