{"id":19146471,"url":"https://github.com/kahsolt/conv2d-kernels-cluster","last_synced_at":"2025-07-11T14:14:52.560Z","repository":{"id":113306664,"uuid":"562420933","full_name":"Kahsolt/conv2d-kernels-cluster","owner":"Kahsolt","description":"Try simplifying a CNN by conv-kernel clustering!","archived":false,"fork":false,"pushed_at":"2023-12-17T08:28:14.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-03T16:28:39.900Z","etag":null,"topics":["clustering","cnn","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kahsolt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-11-06T10:00:50.000Z","updated_at":"2023-12-17T08:55:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"aaefb16f-b64c-441f-87a9-61dbcab5ceb0","html_url":"https://github.com/Kahsolt/conv2d-kernels-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fconv2d-kernels-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fconv2d-kernels-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fconv2d-kernels-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fconv2d-kernels-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kahsolt","download_url":"https://codeload.github.com/Kahsolt/conv2d-kernels-cluster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240229935,"owners_count":19768588,"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":["clustering","cnn","tutorial"],"created_at":"2024-11-09T07:44:14.115Z","updated_at":"2025-02-22T19:49:44.426Z","avatar_url":"https://github.com/Kahsolt.png","language":"Python","readme":"# conv2d-kernels-cluster\n\n    Try simplifying a CNN by conv-kernel clustering!\n\n----\n\nThis is inspired by [https://github.com/Kahsolt/conv2d-kernels](https://github.com/Kahsolt/conv2d-kernels) and [https://github.com/Kahsolt/adversarial-prune](https://github.com/Kahsolt/adversarial-prune). Once we get to know that:\n\n  - NNs are stable to small weights perturbation\n  - there are many duplicated/redundant conv2d kernels in pretrained CNNs\n\nNow consider: what if we replace all the kernels with its clustered centroids, will this network still work well?\n\n结论:\n\n- 用各种方法去合并核都会渐进地导致分类精度下降，是否可以在训练时引入一个正则损失以提高核的多样性？\n- 核的多样性\n  - 第一层 conv 会有大量相似冗余的核 (这个特性是否有助于将对抗样本问题杀死在第一层？)\n  - 所有的 downsample 层都会出现大量相似冗余的核，因为 conv1x1 可能仅仅做了通道扩展\n  - 其他层的核多样性都比较好，尤其是 layer4\n- 核合并后更容易受对抗攻击了\n\n\n### Experiments\n\n⚪ ResNet18 on ImageNet-1k(*):\n\n- Prune all layers\n\n| Model | Accuracy | Note |\n| :-: | :-: | :-: |\n| pretrained | 91.80% | |\n| fixed=0.99 | 90.50% | fix prune ratio |\n| fixed=0.98 | 88.30% |  |\n| fixed=0.95 | 85.30% |  |\n| fixed=0.9  | 64.90% |  |\n| fixed=0.85 | 33.10% |  |\n| fixed=0.8  | 12.80% |  |\n| fixed=0.75 |  3.30% |  |\n| wcss=0.9~1.0  | 83.20% | auto prune ratio by wcss |\n| wcss=0.75~1.0 | 34.70% |  |\n| inertia=1 | **90.50%** | auto prune ratio by inertia |\n| inertia=2 | 85.40% |  |\n| inertia=3 | 83.50% |  |\n| inertia=5 | 72.90% |  |\n\n- Prune only first layer (`--only_first_layer`)\n\n| Model | Accuracy | Note |\n| :-: | :-: | :-: |\n| pretrained | 91.80% | |\n| fixed=0.95   | 91.80% | inertia:  4-14 |\n| fixed=0.75   | 90.20% | inertia:  2.26 |\n| fixed=0.5    | 53.20% | inertia: 19.18 |\n| wcss=0.7~0.8 | 90.60% | inertia:  1.80 |\n| wcss=0.4~0.6 | 51.00% | inertia: 23.82 |\n\n(*) Test data is 1k samples drawn from validtion set of the whole ImageNet\n\n\n### Quick Start\n\n- cluster-based prune a pretrianed model: `python prune.py -M \u003cmodel\u003e`\n- test original pretrained model: `python test.py -M \u003cmodel\u003e`\n- test cluster-based pruned model: `python test.py --ckpt out\\\u003cmodel\u003e_pruned.pth`\n\nℹ you can firstly run `run.cmd` for demo experiments\n\n----\n\nby Armit\n2022/11/05 \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Fconv2d-kernels-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkahsolt%2Fconv2d-kernels-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Fconv2d-kernels-cluster/lists"}