glassInit


NameglassInit JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryglassInit 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.
upload_time2025-07-30 04:26:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords glassinit initialize shortcut pytorch ai neural nn connections skip connections res
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```bash
pip install glassInit
```

## Use
```python
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/>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "glassInit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "glassInit, initialize, shortcut, PyTorch, AI, neural, NN, connections, Skip Connections, Res",
    "author": null,
    "author_email": "Psyche Halo <Psyche@WinsGod.com>",
    "download_url": "https://files.pythonhosted.org/packages/dc/15/c301b153a51803f7e1aafca32dc5f2a0a6c9ca37c5331676030bab7fefe3/glassinit-0.0.3.tar.gz",
    "platform": null,
    "description": "# glassInit\nglassInit 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.  \n\n## \u601d\u8def\u8bf4\u660e\n\u5728\u795e\u7ecf\u7f51\u7edc\u4e2d\u6784\u5efa\u5feb\u6377\u8fde\u63a5/\u8df3\u8dc3\u8fde\u63a5\u65f6\u53c8\u662f\u9700\u8981\u6539\u53d8\u5f62\u72b6,\u5982\u679c\u76f4\u63a5\u4f7f\u7528\u5377\u79ef\u5c42/\u7ebf\u6027\u5c42\u7b49\u4f1a\u56e0\u4e3a\u5176\u521d\u59cb\u5316\u65b9\u5f0f\u5f71\u54cd\u8fde\u63a5\u4e2d\u7684\u68af\u5ea6\u4f20\u64ad,\u800c\u5982\u679c\u5728\u5404\u7ef4\u5ea6\u4e0a\u5206\u522b\u4f7f\u7528\u63d2\u503c\u7f29\u653e\u4f1a\u5bfc\u81f4\u660e\u663e\u7684\u4fe1\u606f\u4e5f\u4f1a\u5f71\u54cd\u68af\u5ea6\u4f20\u64ad. glassInit\u4e13\u7528\u4e8e\u5feb\u6377\u8fde\u63a5/\u8df3\u8dc3\u8fde\u63a5\u4e2d\u7528\u4e8e\u8c03\u6574\u5f20\u91cf\u5c3a\u5bf8\u7684\u5c42,\u5b83\u6784\u5efa\u4e86\u4e00\u4e2a\u63d2\u503c\u77e9\u9635\u5b9e\u73b0\u5728\u6240\u6709\u7ef4\u5ea6\u4e0a\u4e00\u8d77\u63d2\u503c,\u6700\u5927\u9650\u5ea6\u7684\u4fdd\u7559\u4e86\u4fe1\u606f.\n\n## Install\n```bash\npip install glassInit\n```\n\n## Use\n```python\nfrom glassInit import glassInit_\n...\nlinear=torch.nn.Linear(512,2048,bias=False)\nglassInit_(linear.weight,inDim=...,outDim=0,gain=None,zeroMean=True)\n```\n\u5927\u591a\u6570\u65f6\u5019\u4e0d\u9700\u8981\u4f20\u5165\u5916\u90e8gain(\u9ed8\u8ba4\u4e3aNone),\u5982\u679c\u4f20\u5165\u5916\u90e8gain\u5219\u5185\u90e8gain\u4e0d\u751f\u6548.\u8f93\u5165\u5143\u7d20\u6570\u5927\u4e8e\u8f93\u51fa\u5143\u7d20\u6570\u65f6\u5185\u90e8gain\u4e3a1/sqrt(\u8f93\u5165\u7279\u5f81\u6570/\u8f93\u51fa\u7279\u5f81\u6570),\u5426\u5219\u5185\u90e8gain\u4e3a1.\n\n\u9700\u6839\u636e\u77e9\u9635\u5404\u7ef4\u5ea6\u7684\u4f5c\u7528\u586b\u5199inDim\u548coutDim,\u6700\u7ec8\u52a0\u5728\u4e00\u8d77\u7684\u8981\u586b\u5230inDim,\u8f93\u51fa\u65f6\u4ecd\u7136\u5206\u79bb\u7684\u8981\u586b\u5230outDim\n\n\u4e3e\u4f8b\u6765\u8bf4\u5377\u79ef\u5c42\u7684inChannel\u7ef4\u5ea6\u548ckernels\u7ef4\u5ea6\u8981\u586b\u5230inDim\u91cc,outChannel\u7ef4\u5ea6\u8981\u586b\u5230outDim\u91cc\n\n\u8f6c\u7f6e\u5377\u79ef\u8981\u6839\u636e\u8bbe\u5b9a\u53c2\u6570\u540e\u7684\u5177\u4f53\u884c\u4e3a\u51b3\u5b9akernels\u7ef4\u5ea6\u8981\u586b\u5230\u54ea\u91cc,\u53ef\u4ee5\u5148\u5199\u5230outDim\u4e2d\u5c1d\u8bd5\n\n\u5982\u679czeroMean\u4e3aFalse,\u8fd4\u56de\u77e9\u9635\u5c06\u6ca1\u6709\u5c0f\u4e8e\u96f6\u7684\u503c,\u5e76\u4e14\u662f\u63d2\u503c\u77e9\u9635.\u5426\u5219,\u8fd4\u56de\u77e9\u9635\u5c06\u5bf9\u63d2\u503c\u77e9\u9635\u9010\u5143\u7d20\u968f\u673a\u53d6\u53cd.   \n\n\n## HomePage\n<https://github.com/PsycheHalo/glassInit/>\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "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. ",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/PsycheHalo/glassInit",
        "Issues": "https://github.com/PsycheHalo/glassInit/issues"
    },
    "split_keywords": [
        "glassinit",
        " initialize",
        " shortcut",
        " pytorch",
        " ai",
        " neural",
        " nn",
        " connections",
        " skip connections",
        " res"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "55251f33520c2576f491c2eee08a1ee7d0308d9b1f2d5bdb78e206b98575f8ab",
                "md5": "9e53512df9f4cb54ddd0e76eb7c34050",
                "sha256": "30a560ae1dd68e9e6fd9ebeaad5ca4e417492d55887e5049b45188d0100e5ab9"
            },
            "downloads": -1,
            "filename": "glassinit-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9e53512df9f4cb54ddd0e76eb7c34050",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11250,
            "upload_time": "2025-07-30T04:26:17",
            "upload_time_iso_8601": "2025-07-30T04:26:17.226499Z",
            "url": "https://files.pythonhosted.org/packages/55/25/1f33520c2576f491c2eee08a1ee7d0308d9b1f2d5bdb78e206b98575f8ab/glassinit-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dc15c301b153a51803f7e1aafca32dc5f2a0a6c9ca37c5331676030bab7fefe3",
                "md5": "9337f16a84f91aad5fcd95f866c19eb9",
                "sha256": "a2398f9ef2199fbe7545652cfa63c501b1144e72d945aa96c9f45e4c217cb9a0"
            },
            "downloads": -1,
            "filename": "glassinit-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "9337f16a84f91aad5fcd95f866c19eb9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10663,
            "upload_time": "2025-07-30T04:26:18",
            "upload_time_iso_8601": "2025-07-30T04:26:18.725224Z",
            "url": "https://files.pythonhosted.org/packages/dc/15/c301b153a51803f7e1aafca32dc5f2a0a6c9ca37c5331676030bab7fefe3/glassinit-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-30 04:26:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PsycheHalo",
    "github_project": "glassInit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "glassinit"
}
        
Elapsed time: 0.63733s