{"id":28690893,"url":"https://github.com/weltxing/fastconv","last_synced_at":"2025-06-14T06:07:59.504Z","repository":{"id":112059732,"uuid":"487471128","full_name":"WeltXing/FastConv","owner":"WeltXing","description":"卷积操作(1d, 2d)的快速实现","archived":false,"fork":false,"pushed_at":"2022-05-19T02:38:12.000Z","size":119,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-23T12:43:49.088Z","etag":null,"topics":["convolution","convolutional-neural-networks","numpy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WeltXing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-01T07:16:07.000Z","updated_at":"2024-10-28T14:40:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"c21061cb-1a72-49a9-961b-b6d1e9303d27","html_url":"https://github.com/WeltXing/FastConv","commit_stats":null,"previous_names":["weltxing/fastconv"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WeltXing/FastConv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeltXing%2FFastConv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeltXing%2FFastConv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeltXing%2FFastConv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeltXing%2FFastConv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WeltXing","download_url":"https://codeload.github.com/WeltXing/FastConv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeltXing%2FFastConv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259768621,"owners_count":22908232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolution","convolutional-neural-networks","numpy"],"created_at":"2025-06-14T06:07:58.852Z","updated_at":"2025-06-14T06:07:59.484Z","avatar_url":"https://github.com/WeltXing.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastConv\n\n使用NumPy实现1d和2d卷积，直接实现需要多重循环，比如二维卷积的代码：\n\n```python\nfor i in range(N):\n    for j in range(self.out_channels):\n        for k in range(h_out):\n            for l in range(w_out):\n                for m in range(in_channels):\n                    for row in range(self.kernel_size):\n                        for col in range(self.kernel_size):\n                            output[i, j, k,\n                                    l] += data[i, m, k * stride + row,\n                                                l * stride +\n                                                col] * kernel[j, m, row,\n                                                            col]\n```\n\n因此我们尝试各种方法，避免NumPy基础卷积操作中的多重循环：样本循环、卷积循环、通道循环，从而加速卷积过程。\n\n## Conv1d\n\n1. 利用`scipy.ndimage.correlate1d`消除样本循环和卷积循环；\n2. 利用NumPy的广播机制消除样本循环和一部分通道循环；\n3. 利用类似im2col策略消除大部分循环；\n4. 使用im2col+strided策略消除所有循环.\n\n四种方法和baseline的比较（横轴为输入特征数，纵轴为时间的对数，具体实验设置参考[test.py](/src/test.py)，图中的`strided`就是`im2col+strided`方法）\n\n![1](img/test.png)\n\n最优两种方法和PyTorch的对比：\n\n![2](img/test_im2col.png)\n\n## Conv2d\n\n1. 利用`scipy.ndimage.correlate`消除样本循环和卷积循环；\n2. 利用NumPy的广播机制消除样本循环和一部分通道循环；\n3. 利用im2col策略消除所有循环。\n4. ...\n\n## Reference(Updating)\n\n- \u003chttps://welts.xyz/2022/05/02/fast_conv/\u003e;\n- ...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweltxing%2Ffastconv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweltxing%2Ffastconv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweltxing%2Ffastconv/lists"}