title: When does Pytorch initialize parameters?
body: <p>I’m now writing my own network with Pytorch. And I want to use a pretrained model in my net. Here is my overwriting <strong>init</strong>() code:</p>
  <pre class="lang-py prettyprint-override"><code>class Generator(nn.Module):
      def __init__(self) -&gt; None:
          super(Generator, self).__init__()
          model_path = &quot;somedir&quot;
          chekpoint = torch.load(model_path)
          h_model = H_model()
          h_model.load_state_dict(chekpoint['model'])
          # 设置为测试模式
          h_model.eval()
          self.H_model = h_model
          self.unet = UNet(enc_chs=(9,64,128,256,512), dec_chs=(512, 256, 128, 64), num_class=3, retain_dim=False, out_sz=(304, 304))
  </code></pre>
  <p>Here, the h_model is loaded from checkpoint which I’ve trained it well.
  My question is that after the initialization, will the parameter in h_model changed(Are the pretrained parameters vaule being modified by some function?)? And why(I mean how does Pytorch treat self-defined layer when it initializes parameters? And when does Pytorch initialize parameters?)</p>