Skip to main content

glassInit is a way to initialize the parameters of a neural network layer @pytorch. 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.

Project description

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/sqrt(输入特征数/输出特征数),否则内部gain为1.

需根据矩阵各维度的作用填写inDim和outDim,最终加在一起的要填到inDim,输出时仍然分离的要填到outDim

举例来说卷积层的inChannel维度和kernels维度要填到inDim里,outChannel维度要填到outDim里

转置卷积要根据设定参数后的具体行为决定kernels维度要填到哪里,可以先写到outDim中尝试

如果zeroMean为False,返回矩阵将没有小于零的值,并且是插值矩阵.否则,返回矩阵将对插值矩阵逐元素随机取反.

HomePage

https://github.com/PsycheHalo/glassInit/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glassinit-0.0.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glassinit-0.0.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file glassinit-0.0.2.tar.gz.

File metadata

  • Download URL: glassinit-0.0.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for glassinit-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2704483f886399c2d18f581da7e436e44faecf1d287e2e089c8a1f64e8a73d21
MD5 24d01c84233c942e09b85464e96d4e46
BLAKE2b-256 cde84b52717cda77df9f6c9222ba281ccdfd47236317cb56189f4f775e7b9f39

See more details on using hashes here.

Provenance

The following attestation bundles were made for glassinit-0.0.2.tar.gz:

Publisher: python-publish.yml on PsycheHalo/glassInit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glassinit-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: glassinit-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for glassinit-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 feef078b1d82dedc71eb81231db8604458266433df59157972e4509b32972cad
MD5 ff767afe05bf0c78d3b144ac37478ccd
BLAKE2b-256 45fafcb007bce5fb4de06155d03f2e88966d9f3a4c43e71fabe2712805a2a026

See more details on using hashes here.

Provenance

The following attestation bundles were made for glassinit-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on PsycheHalo/glassInit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page