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.4.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.4-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: glassinit-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 02dcfc7b823df3a1e382e0de40ddf240fae6cc20705d7854746b3bb9ea5704c7
MD5 d1057f3a784a48dc87e7e932b839fbad
BLAKE2b-256 126196dba4e61405ab478cc471d0883515907a862752580d191ecd8dc1c96e2b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: glassinit-0.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2ebae72b4195c92aa4c0d7f739ea3dbd5785b3d7f3737b834daee630f5a7f3d9
MD5 1dea0cb61c62377bb4b16cccf8045277
BLAKE2b-256 db8366b6810c9ebb1858b6c5432742cadd1bb1a25714c0cf295eda2bbb59b956

See more details on using hashes here.

Provenance

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