How to get the inner module of Unet?
I created a UNet with the the UnetGenerator. You can find the resulting structure here.


How do I get the module Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1))?
How do I get the module (5): ConvTranspose2d(256, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1))?


I want to get the inner modules to change the attributes of certain layers.
I tried something like net.modules(i).modules(i), but it doesn't work. I refer the docs, I haven't get a good idea to do it.

My initial intention is to change the attributes of certain layers when training. I may add a custom layer myLayer, in which self.mode='normal'. When training, I hope I can change its attribute myLayer.mode = 'capture' to make it change its behaviour in training.

All the subclasses of nn.Module has an attribute called children. Which you will be able to access using the code below.

unet = UnetGenerator(512,512,4)
layers = list(unet.children())
len(layers)


For the network I created using the above code , I can access one of the layers inside the network and change the properties like below.

l = layers[0]
conv = list(l.children())[0][0]
conv.kernel_size = (2,2)


If you are training the network without using any pre-trained weights then you could make the changes in the source code before you create the network object.
