glassInit
glassInit is a way to initialize the parameters of a neural network layer. It is suitable for shortcut connections where tensor sizes need to be adjusted. The flow of information between forward and backward propagation is maximized while adjusting the tensor size.
思路说明
在神经网络中构建快捷连接/跳跃连接时又是需要改变形状,如果直接使用卷积层/线性层等会因为其初始化方式影响连接中的梯度传播,而如果在各维度上分别使用插值缩放会导致明显的信息也会影响梯度传播. glassInit专用于快捷连接/跳跃连接中用于调整张量尺寸的层,它构建了一个插值矩阵实现在所有维度上一起插值,最大限度的保留了信息.
Install
pip install glassInit
Use
from glassInit import glassInit_
...
linear=torch.nn.Linear(512,2048,bias=False)
glassInit_(linear.weight,inDim=...,outDim=0,gain=None,zeroMean=True)
大多数时候不需要传入外部gain(默认为None)如果传入外部gain则内部gain不生效.
输入元素数小于输出元素数且关闭稀疏时内部gain为1. 否则内部gain为sqrt(输出元素数/输入元素数)
需根据矩阵各维度的作用填写inDim和outDim,最终加在一起的要填到inDim,输出时仍然分离的要填到outDim
举例来说卷积层的inChannel维度和kernels维度要填到inDim里,outChannel维度要填到outDim里
转置卷积要根据设定参数后的具体行为决定kernels维度要填到哪里,可以先写道inDim中尝试
如果zeroMean为False,返回矩阵将没有小于零的值,并且是插值矩阵.否则,返回矩阵将对插值矩阵逐元素随机取反.
如果输入元素数大于输出元素数或关闭稀疏,矩阵实现线性插值,否则是插0插值.两种插值均为循环边界条件.
HomePage
Metadata
Release files for glassInit 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| glassinit-0.0.6.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| glassinit-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / glassinit-0.0.6.tar.gz
| Download URL | glassinit-0.0.6.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
136a1ce3a76852c476a8560a242c7cc1893c20df03d914e06df2d8b3c606aff1
|
|
BLAKE2b-256 checksum How to use checksums |
8c559afba18ef33e97dc6ce010e9a65654512b30dd1b0dbf3cf9765eea1bac29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 6, 2025.
Transparency logRelease files / glassinit-0.0.6-py3-none-any.whl
| Download URL | glassinit-0.0.6-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
795b6d1183e8eac35267cd847d372ddbe3e5173bb295f5c8e255aba4759045ac
|
|
BLAKE2b-256 checksum How to use checksums |
0af958a94d9dbc81560ea75bb916c7275ecf7397aee24bc369e55cf867c69ec4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 6, 2025.
Transparency log