Will weights initialized code be executed again during training after being initialized?

In the Actor Critic framework, suppose I have an actor like this(fan_in_initializer() is just a self-defined method),
When I create an actor instance, line 10, 13 and 16 will be executed once, then if I train the model, will these lines of code be executed again?

class Actor(nn.Module):

    def __init__(self, s_dim, a_dim):
        super(Actor, self).__init__()

        self.s_dim = s_dim
        self.a_dim = a_dim

        self.fc1 = nn.Linear(s_dim, 512)
        self.fc1.weight.data = fan_in_initializer(self.fc1.weight.data.size()) # line 10

        self.fc2 = nn.Linear(512, 256)
        self.fc2.weight.data = fan_in_initializer(self.fc2.weight.data.size()) # line 13

        self.fc3 = nn.Linear(256, a_dim)
        self.fc3.weight.data.uniform_(-EPS,EPS) # line 16

    def forward(self, s):
        x = F.relu(self.fc1(s))
        x = F.relu(self.fc2(x))
        a = F.tanh(self.fc3(x))
        return a

Thanks in advance.

No, the __init__ method will only be called, when you create an instance of the model via:

model = Actor(1, 1)

During training the forward method will be called.

1 Like