hnn


Namehnn JSON
Version 0.0.3.5 PyPI version JSON
download
home_pagehttps://github.com/openBII/HNN
SummaryA programming framework based on PyTorch for hybrid neural networks with automatic quantization
upload_time2023-04-02 08:25:29
maintainer
docs_urlNone
authorHuanyu
requires_python
licenseApache License 2.0
keywords hybrid neural networks spiking neural networks quantization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Hybrid Programming Framework

## 简介

HNN编程框架基于PyTorch进行开发,提供了编写ANN、SNN、HNN模型的编程接口,同时可以支持通过此编程框架描述的ANN、SNN模型的自动化量化(HNN的自动化量化仍在开发中),可以支持后训练静态量化和量化感知训练。下面对SNN和HNN编程进行简要说明:
- SNN编程由一系列基本SNN操作组成,通过这些基本操作可以组成灵活的、功能丰富的扩展LIF神经元模型,用户也可以基于这些基本操作实现自定义的神经元模型。
- HNN编程中的HNN主要指[1]中以Hybrid Unit (HU)为转换单元来连接ANN和SNN网络的混合网络,编程框架中实现了可扩展的HU,用户可使用编程框架中提供的各种HU或自定义HU。

此框架的开发过程中考虑了与BiMap的融合,通过此编程框架描述的网络可以进一步被BiMap中的编译系统编译部署到支持的类脑计算芯片上。

HNN编程框架的详细开发及使用文档请见工程文档。

## 基本使用

通过pip安装:
```bash
pip install hnn
```

注:目前因为ONNX版本兼容问题,Pytorch需要使用1.11.0版本

`examples`文件夹下为通过此编程框架写出的一些ANN、SNN、HNN模型,以需要量化的SNN为例,SNN模型需要继承`src.snn`中的`QModel`类,并通过`QConv2d`, `QLinear`, `QLIF`等算子来搭建网络:
```python
from src.snn import QModel, QLinear, QLIF


class SNN(QModel):
    def __init__(self, in_channels, T, num_classes=10):
        super(SNN, self).__init__(time_window_size=T)
        self.linear = QLinear(
            in_features=in_channels, out_features=num_classes)
        self.lif = QLIF(v_th=1, v_leaky_alpha=0.9,
                        v_leaky_beta=0, v_reset=0)
```


## 参考引用

如果使用到本编程框架的HNN部分,请引用[1]:

    @article{Zhao2022,
    doi = {10.1038/s41467-022-30964-7},
    url = {https://doi.org/10.1038/s41467-022-30964-7},
    year = {2022},
    month = jun,
    publisher = {Springer Science and Business Media {LLC}},
    volume = {13},
    number = {1},
    author = {Rong Zhao and Zheyu Yang and Hao Zheng and Yujie Wu and Faqiang Liu and Zhenzhi Wu and Lukai Li and Feng Chen and Seng Song and Jun Zhu and Wenli Zhang and Haoyu Huang and Mingkun Xu and Kaifeng Sheng and Qianbo Yin and Jing Pei and Guoqi Li and Youhui Zhang and Mingguo Zhao and Luping Shi},
    title = {A framework for the general design and computation of hybrid neural networks},
    journal = {Nature Communications}
    }

本工程的SNN和HNN编程部分参考或复用了部分[SpikingJelly](https://github.com/fangwei123456/spikingjelly)的代码:

    @misc{SpikingJelly,
        title = {SpikingJelly},
        author = {Fang, Wei and Chen, Yanqi and Ding, Jianhao and Chen, Ding and Yu, Zhaofei and Zhou, Huihui and Timothée Masquelier and Tian, Yonghong and other contributors},
        year = {2020},
        howpublished = {\url{https://github.com/fangwei123456/spikingjelly}},
        note = {Accessed: YYYY-MM-DD},
    }



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/openBII/HNN",
    "name": "hnn",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "hybrid neural networks,spiking neural networks,quantization",
    "author": "Huanyu",
    "author_email": "huanyu.qu@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/56/1e/b526b0b09852547eb9a772331c50e802b2c45cf45ee437f8a07c5ad648a6/hnn-0.0.3.5.tar.gz",
    "platform": "any",
    "description": "# Hybrid Programming Framework\n\n## \u7b80\u4ecb\n\nHNN\u7f16\u7a0b\u6846\u67b6\u57fa\u4e8ePyTorch\u8fdb\u884c\u5f00\u53d1\uff0c\u63d0\u4f9b\u4e86\u7f16\u5199ANN\u3001SNN\u3001HNN\u6a21\u578b\u7684\u7f16\u7a0b\u63a5\u53e3\uff0c\u540c\u65f6\u53ef\u4ee5\u652f\u6301\u901a\u8fc7\u6b64\u7f16\u7a0b\u6846\u67b6\u63cf\u8ff0\u7684ANN\u3001SNN\u6a21\u578b\u7684\u81ea\u52a8\u5316\u91cf\u5316\uff08HNN\u7684\u81ea\u52a8\u5316\u91cf\u5316\u4ecd\u5728\u5f00\u53d1\u4e2d\uff09\uff0c\u53ef\u4ee5\u652f\u6301\u540e\u8bad\u7ec3\u9759\u6001\u91cf\u5316\u548c\u91cf\u5316\u611f\u77e5\u8bad\u7ec3\u3002\u4e0b\u9762\u5bf9SNN\u548cHNN\u7f16\u7a0b\u8fdb\u884c\u7b80\u8981\u8bf4\u660e\uff1a\n- SNN\u7f16\u7a0b\u7531\u4e00\u7cfb\u5217\u57fa\u672cSNN\u64cd\u4f5c\u7ec4\u6210\uff0c\u901a\u8fc7\u8fd9\u4e9b\u57fa\u672c\u64cd\u4f5c\u53ef\u4ee5\u7ec4\u6210\u7075\u6d3b\u7684\u3001\u529f\u80fd\u4e30\u5bcc\u7684\u6269\u5c55LIF\u795e\u7ecf\u5143\u6a21\u578b\uff0c\u7528\u6237\u4e5f\u53ef\u4ee5\u57fa\u4e8e\u8fd9\u4e9b\u57fa\u672c\u64cd\u4f5c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u795e\u7ecf\u5143\u6a21\u578b\u3002\n- HNN\u7f16\u7a0b\u4e2d\u7684HNN\u4e3b\u8981\u6307[1]\u4e2d\u4ee5Hybrid Unit (HU)\u4e3a\u8f6c\u6362\u5355\u5143\u6765\u8fde\u63a5ANN\u548cSNN\u7f51\u7edc\u7684\u6df7\u5408\u7f51\u7edc\uff0c\u7f16\u7a0b\u6846\u67b6\u4e2d\u5b9e\u73b0\u4e86\u53ef\u6269\u5c55\u7684HU\uff0c\u7528\u6237\u53ef\u4f7f\u7528\u7f16\u7a0b\u6846\u67b6\u4e2d\u63d0\u4f9b\u7684\u5404\u79cdHU\u6216\u81ea\u5b9a\u4e49HU\u3002\n\n\u6b64\u6846\u67b6\u7684\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u8003\u8651\u4e86\u4e0eBiMap\u7684\u878d\u5408\uff0c\u901a\u8fc7\u6b64\u7f16\u7a0b\u6846\u67b6\u63cf\u8ff0\u7684\u7f51\u7edc\u53ef\u4ee5\u8fdb\u4e00\u6b65\u88abBiMap\u4e2d\u7684\u7f16\u8bd1\u7cfb\u7edf\u7f16\u8bd1\u90e8\u7f72\u5230\u652f\u6301\u7684\u7c7b\u8111\u8ba1\u7b97\u82af\u7247\u4e0a\u3002\n\nHNN\u7f16\u7a0b\u6846\u67b6\u7684\u8be6\u7ec6\u5f00\u53d1\u53ca\u4f7f\u7528\u6587\u6863\u8bf7\u89c1\u5de5\u7a0b\u6587\u6863\u3002\n\n## \u57fa\u672c\u4f7f\u7528\n\n\u901a\u8fc7pip\u5b89\u88c5\uff1a\n```bash\npip install hnn\n```\n\n\u6ce8\uff1a\u76ee\u524d\u56e0\u4e3aONNX\u7248\u672c\u517c\u5bb9\u95ee\u9898\uff0cPytorch\u9700\u8981\u4f7f\u75281.11.0\u7248\u672c\n\n`examples`\u6587\u4ef6\u5939\u4e0b\u4e3a\u901a\u8fc7\u6b64\u7f16\u7a0b\u6846\u67b6\u5199\u51fa\u7684\u4e00\u4e9bANN\u3001SNN\u3001HNN\u6a21\u578b\uff0c\u4ee5\u9700\u8981\u91cf\u5316\u7684SNN\u4e3a\u4f8b\uff0cSNN\u6a21\u578b\u9700\u8981\u7ee7\u627f`src.snn`\u4e2d\u7684`QModel`\u7c7b\uff0c\u5e76\u901a\u8fc7`QConv2d`, `QLinear`, `QLIF`\u7b49\u7b97\u5b50\u6765\u642d\u5efa\u7f51\u7edc\uff1a\n```python\nfrom src.snn import QModel, QLinear, QLIF\n\n\nclass SNN(QModel):\n    def __init__(self, in_channels, T, num_classes=10):\n        super(SNN, self).__init__(time_window_size=T)\n        self.linear = QLinear(\n            in_features=in_channels, out_features=num_classes)\n        self.lif = QLIF(v_th=1, v_leaky_alpha=0.9,\n                        v_leaky_beta=0, v_reset=0)\n```\n\n\n## \u53c2\u8003\u5f15\u7528\n\n\u5982\u679c\u4f7f\u7528\u5230\u672c\u7f16\u7a0b\u6846\u67b6\u7684HNN\u90e8\u5206\uff0c\u8bf7\u5f15\u7528[1]\uff1a\n\n    @article{Zhao2022,\n    doi = {10.1038/s41467-022-30964-7},\n    url = {https://doi.org/10.1038/s41467-022-30964-7},\n    year = {2022},\n    month = jun,\n    publisher = {Springer Science and Business Media {LLC}},\n    volume = {13},\n    number = {1},\n    author = {Rong Zhao and Zheyu Yang and Hao Zheng and Yujie Wu and Faqiang Liu and Zhenzhi Wu and Lukai Li and Feng Chen and Seng Song and Jun Zhu and Wenli Zhang and Haoyu Huang and Mingkun Xu and Kaifeng Sheng and Qianbo Yin and Jing Pei and Guoqi Li and Youhui Zhang and Mingguo Zhao and Luping Shi},\n    title = {A framework for the general design and computation of hybrid neural networks},\n    journal = {Nature Communications}\n    }\n\n\u672c\u5de5\u7a0b\u7684SNN\u548cHNN\u7f16\u7a0b\u90e8\u5206\u53c2\u8003\u6216\u590d\u7528\u4e86\u90e8\u5206[SpikingJelly](https://github.com/fangwei123456/spikingjelly)\u7684\u4ee3\u7801\uff1a\n\n    @misc{SpikingJelly,\n        title = {SpikingJelly},\n        author = {Fang, Wei and Chen, Yanqi and Ding, Jianhao and Chen, Ding and Yu, Zhaofei and Zhou, Huihui and Timoth\u00e9e Masquelier and Tian, Yonghong and other contributors},\n        year = {2020},\n        howpublished = {\\url{https://github.com/fangwei123456/spikingjelly}},\n        note = {Accessed: YYYY-MM-DD},\n    }\n\n\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "A programming framework based on PyTorch for hybrid neural networks with automatic quantization",
    "version": "0.0.3.5",
    "split_keywords": [
        "hybrid neural networks",
        "spiking neural networks",
        "quantization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "561eb526b0b09852547eb9a772331c50e802b2c45cf45ee437f8a07c5ad648a6",
                "md5": "d2db876391735f74a9bf09de8f6b5942",
                "sha256": "bba01e7bbd3fe2e74b97bc9d596bc1d14d1ff7262b612a82caa887c861ab2509"
            },
            "downloads": -1,
            "filename": "hnn-0.0.3.5.tar.gz",
            "has_sig": false,
            "md5_digest": "d2db876391735f74a9bf09de8f6b5942",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 33351,
            "upload_time": "2023-04-02T08:25:29",
            "upload_time_iso_8601": "2023-04-02T08:25:29.984873Z",
            "url": "https://files.pythonhosted.org/packages/56/1e/b526b0b09852547eb9a772331c50e802b2c45cf45ee437f8a07c5ad648a6/hnn-0.0.3.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-02 08:25:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "openBII",
    "github_project": "HNN",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "hnn"
}
        
Elapsed time: 0.11230s