When I use self.__dict__[] to define a layer, it didn't show in the net.state_dict()

below is the screenshot

I’m assuming your intent is to programmatically assign a name for the submodule. Try one of the following:

class test(nn.Module):
    def __init__(self):
        super(test, self).__init__()
        self.__setattr__('a' + '_1', nn.Conv2d(3, 3, kernel_size=3))
        self.add_module('a' + '_2', nn.Conv2d(3, 3, kernel_size=3))
        
    def forward(self, x):
        x = self.a_1(x)
        x = self.a_2(x)
        return x

net = test()
net