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.1.tar.gz (7.9 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.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: glassinit-0.0.1.tar.gz
  • Upload date:
  • Size: 7.9 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.1.tar.gz
Algorithm Hash digest
SHA256 80d481800e88e0db8da86b62ccbdaa752f73cb3a03fe3fce0ba08a8b393ff22f
MD5 7002fd08f3a5048a8dcac439ff2346af
BLAKE2b-256 1e2f0dda31500c445554db321b21c4c0af5411c840f940da8dfee5b5873f4026

See more details on using hashes here.

Provenance

The following attestation bundles were made for glassinit-0.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: glassinit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6554be1abbd73f629961e430c6142077062b3c35100d8091faf3b1302bf6c98c
MD5 a8aa0a37b4e7d468661397a3aeb3166d
BLAKE2b-256 b7ac66d1149d57143aa2e02c61ff83d9fc2067e049e4f2eb8721d1eb4b6055b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for glassinit-0.0.1-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