{"id":25423270,"url":"https://github.com/alykhantejani/nninit","last_synced_at":"2025-10-31T14:30:33.147Z","repository":{"id":57446446,"uuid":"82231509","full_name":"alykhantejani/nninit","owner":"alykhantejani","description":"Weight initialization schemes for PyTorch nn.Modules","archived":false,"fork":false,"pushed_at":"2017-03-02T08:48:32.000Z","size":35,"stargazers_count":70,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-20T10:35:59.125Z","etag":null,"topics":["pytorch","weight-initialization-schemes"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alykhantejani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-16T22:15:31.000Z","updated_at":"2024-01-04T16:11:31.000Z","dependencies_parsed_at":"2022-09-02T23:41:25.780Z","dependency_job_id":null,"html_url":"https://github.com/alykhantejani/nninit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alykhantejani%2Fnninit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alykhantejani%2Fnninit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alykhantejani%2Fnninit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alykhantejani%2Fnninit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alykhantejani","download_url":"https://codeload.github.com/alykhantejani/nninit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239206338,"owners_count":19599938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytorch","weight-initialization-schemes"],"created_at":"2025-02-16T22:27:07.738Z","updated_at":"2025-10-31T14:30:33.108Z","avatar_url":"https://github.com/alykhantejani.png","language":"Python","funding_links":[],"categories":["Paper implementations｜论文实现","Paper implementations"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"readme":"# nninit\n\nWeight initialization schemes for PyTorch nn.Modules. This is a port of the popular [nninit](https://github.com/Kaixhin/nninit) for [Torch7](https://github.com/torch/torch7) by [@kaixhin](https://github.com/Kaixhin/).\n\n##Update\n\nThis repo has been merged into [PyTorch's nn module](https://github.com/pytorch/pytorch/blob/master/torch/nn/init.py), I recommend you use that version going forward.\n\n###PyTorch Example\n```python\nimport nninit\nfrom torch import nn\nimport torch.nn.init as init\nimport numpy as np\n\nclass Net(nn.Module):\n  def __init__(self):\n     super(Net, self).__init__()\n     self.conv1 = nn.Conv2d(5, 10, (3, 3))\n     init.xavier_uniform(self.conv1.weight, gain=np.sqrt(2))\n     init.constant(self.conv1.bias, 0.1)\n\nnetwork = Net()\n```\n\n\n\n##Installation\nClone the repo and run `python setup install`\n\n##Usage\n```python\nimport nninit\nfrom torch import nn\nimport numpy as np\n\nclass Net(nn.Module):\n  def __init__(self):\n     super(Net, self).__init__()\n     self.conv1 = nn.Conv2d(5, 10, (3, 3))\n     nninit.xavier_uniform(self.conv1.weight, gain=np.sqrt(2))\n     nninit.constant(self.conv1.bias, 0.1)\n\nnetwork = Net()\n```\n\n##Supported Schemes\n* **`nninit.uniform(tensor, a=0, b=1)`** - Fills `tensor` with values from a uniform, U(a,b)\n* **`nninit.normal(tensor, mean=0, std=1)`** - Fills `tensor` with values drawn from a normal distribution with the given mean and std\n* **`nninit.constant(tensor, val)`** - Fills `tensor` with the constant `val`\n* **`nninit.xavier_uniform(tensor, gain=1)`** - Fills `tensor` with values according to the method described in [\"Understanding the difficulty of training deep feedforward neural networks\" - Glorot, X. and Bengio, Y.](http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf), using a uniform distribution.\n* **`nninit.xavier_normal(tensor, gain=1)`** - Fills `tensor` with values according to the method described in [\"Understanding the difficulty of training deep feedforward neural networks\" - Glorot, X. and Bengio, Y.](http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf), using a normal distribution.\n* **`nninit.kaiming_uniform(tensor, gain=1)`** - Fills `tensor` with values according to the method described in [\"Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification\" - He, K. et al.](https://arxiv.org/abs/1502.01852) using a uniform distribution.\n* **`nninit.kaiming_normal(tensor, gain=1)`** - Fills `tensor` with values according to the method described in [\"Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification\" - He, K. et al.](https://arxiv.org/abs/1502.01852) using a normal distribution.\n* **`nninit.orthogonal(tensor, gain=1)`** - Fills the `tensor` with a (semi) orthogonal matrix. Reference: [\"Exact solutions to the nonlinear dynamics of learning in deep linear neural networks\" - Saxe, A. et al.](https://arxiv.org/abs/1312.6120)\n* **`nninit.sparse(tensor, sparsity, std=0.01)`** - Fills the 2D `tensor` as a sparse matrix, where the non-zero elements will be drawn from a normal distribution with mean=0 and std=`std`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falykhantejani%2Fnninit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falykhantejani%2Fnninit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falykhantejani%2Fnninit/lists"}