r""" Initialize model parameters using Xavier initialization.
(self)
| 800 | return out |
| 801 | |
| 802 | def init_weights(self): |
| 803 | r""" |
| 804 | Initialize model parameters using Xavier initialization. |
| 805 | """ |
| 806 | |
| 807 | # basic init |
| 808 | for m in self.modules(): |
| 809 | if isinstance(m, nn.Linear): |
| 810 | nn.init.xavier_uniform_(m.weight) |
| 811 | if m.bias is not None: |
| 812 | nn.init.zeros_(m.bias) |
| 813 | |
| 814 | # init embeddings |
| 815 | nn.init.xavier_uniform_(self.patch_embedding.weight.flatten(1)) |
| 816 | for m in self.text_embedding.modules(): |
| 817 | if isinstance(m, nn.Linear): |
| 818 | nn.init.normal_(m.weight, std=.02) |
| 819 | for m in self.time_embedding.modules(): |
| 820 | if isinstance(m, nn.Linear): |
| 821 | nn.init.normal_(m.weight, std=.02) |
| 822 | |
| 823 | # init output layer |
| 824 | nn.init.zeros_(self.head.head.weight) |