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. 否则内部gain为sqrt(输出元素数/输入元素数)

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

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

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

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

如果输入元素数大于输出元素数或关闭稀疏,矩阵实现线性插值,否则是插0插值.两种插值均为循环边界条件.

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.6.tar.gz (11.0 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.6-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: glassinit-0.0.6.tar.gz
  • Upload date:
  • Size: 11.0 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.6.tar.gz
Algorithm Hash digest
SHA256 136a1ce3a76852c476a8560a242c7cc1893c20df03d914e06df2d8b3c606aff1
MD5 89a6344d69c4a7ec104ccc56fa14ff71
BLAKE2b-256 8c559afba18ef33e97dc6ce010e9a65654512b30dd1b0dbf3cf9765eea1bac29

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: glassinit-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.7 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 795b6d1183e8eac35267cd847d372ddbe3e5173bb295f5c8e255aba4759045ac
MD5 d525a924e8d36e92f2c26e4bb28aa97a
BLAKE2b-256 0af958a94d9dbc81560ea75bb916c7275ecf7397aee24bc369e55cf867c69ec4

See more details on using hashes here.

Provenance

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