{"id":39143899,"url":"https://github.com/paulgavrikov/torchconvview","last_synced_at":"2026-01-17T21:32:58.466Z","repository":{"id":65549226,"uuid":"594093073","full_name":"paulgavrikov/torchconvview","owner":"paulgavrikov","description":"A library for PyTorch convolution layer visualizations.","archived":false,"fork":false,"pushed_at":"2024-10-19T13:11:02.000Z","size":408,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-26T14:26:13.822Z","etag":null,"topics":["cnn","computer-vision","python","pytorch","torch","torchvision"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc-by-sa-4.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulgavrikov.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}},"created_at":"2023-01-27T15:29:29.000Z","updated_at":"2024-10-19T13:11:06.000Z","dependencies_parsed_at":"2023-02-15T18:31:18.830Z","dependency_job_id":null,"html_url":"https://github.com/paulgavrikov/torchconvview","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/paulgavrikov/torchconvview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgavrikov%2Ftorchconvview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgavrikov%2Ftorchconvview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgavrikov%2Ftorchconvview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgavrikov%2Ftorchconvview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulgavrikov","download_url":"https://codeload.github.com/paulgavrikov/torchconvview/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgavrikov%2Ftorchconvview/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28518627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T18:55:29.170Z","status":"ssl_error","status_checked_at":"2026-01-17T18:55:03.375Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cnn","computer-vision","python","pytorch","torch","torchvision"],"created_at":"2026-01-17T21:32:57.794Z","updated_at":"2026-01-17T21:32:58.443Z","avatar_url":"https://github.com/paulgavrikov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# torchconvview\n\n[![Latest Version](https://img.shields.io/pypi/v/torchconvview.svg?color=green)](https://pypi.python.org/pypi/torchconvview)\n[![pytest](https://github.com/paulgavrikov/torchconvview/actions/workflows/pytest.yml/badge.svg)](https://github.com/paulgavrikov/torchconvview/actions/workflows/pytest.yml)\n[![CC BY-SA 4.0][cc-by-sa-shield]][cc-by-sa]\n\n\n[cc-by-sa]: http://creativecommons.org/licenses/by-sa/4.0/\n[cc-by-sa-image]: https://licensebuttons.net/l/by-sa/4.0/88x31.png\n[cc-by-sa-shield]: https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg\n\n*A library for PyTorch convolution layer visualizations via matplotlib plots.*\n\n\n## Installation\nTo install published releases from PyPi execute:\n```bash\npip install torchconvview\n```\nTo update torchconvview to the latest available version, add the `--upgrade` flag to the above commands.\n\nIf you want the latest (potentially unstable) features you can also directly install from the github main branch:\n```bash\npip install git+https://github.com/paulgavrikov/torchconvview\n```\n\n## Usage\n\n```python\nfrom torchconvview import plot_conv, plot_conv_rgb, PCAView\nimport matplotlib.pyplot as plt\n\n# Replace this with your own model. As an example,\n# we will use an ImageNet pretrained ResNet-18.\nimport torchvision\nmodel = torchvision.models.resnet18(pretrained=True)\n```\n### General\n\nAll `plot_...` functions return a tuple of the matplotlib figure and axes which allow you to customize the plot to your needs. Also most of these functions accept the `img_scale` argument which allows you to specify a multiplier to the resolution.\n\n### Visualize kernels in the convolution layers\nJust pass the convolution weight as tensor or numpy into `plot_conv` and you'll get a matplotlib figure of the kernels! Each column is one channel/filter, i.e. this stack of kernels generates a feature-map from all input maps.\n```python\nplot_conv(model.layer1[1].conv2.weight)\nplt.show()\n```\n\u003cimg src=\"docs/fig/output_plot_conv.png\" width=\"30%\"\u003e\n\n### Visualize the first layer\nIf you have a convolution layer with RGB input (e.g. often the first layer), the you can visualize entire filters. This function maps all kernels to their respective color. Note that this only work on convolution layers with 3 input channels and only produces meaningfull results if these channels are R, G, B feature-maps!\n\n```python\nplot_conv_rgb(model.conv1.weight)\nplt.show()\n```\n\u003cimg src=\"docs/fig/output_plot_conv_rgb.png\" width=\"100%\"\u003e\n\n### PCA of convolution weights\nYou can also compute the eigenimages/basis vectors of the kernels by using the `PCAView` class. Under the hood it will do a PCA for you. Note, that currently this requires the `scikit-learn` module.\n\n```python\npcaview = PCAView(model.conv1.weight)\npcaview.plot_conv()\nplt.show()\n```\n\u003cimg src=\"docs/fig/output_pcaview_plot_conv.png\" width=\"10%\"\u003e\n\nAnd to get a handy barplot of the explained variance ratio:\n```python\npcaview.plot_variance_ratio()\nplt.show()\n```\n\u003cimg src=\"docs/fig/output_pcaview_plot_variance_ratio.png\" width=\"30%\"\u003e\n\n\n## Citation\n\nPlease consider citing our publication if this libary was helpfull to you.\n```\n@InProceedings{Gavrikov_2022_CVPR,\n    author    = {Gavrikov, Paul and Keuper, Janis},\n    title     = {CNN Filter DB: An Empirical Investigation of Trained Convolutional Filters},\n    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},\n    month     = {June},\n    year      = {2022},\n    pages     = {19066-19076}\n}\n```\n\n## Legal\n\nThis work is licensed under a\n[Creative Commons Attribution-ShareAlike 4.0 International License][cc-by-sa].\n\nFunded by the Ministry for Science, Research and Arts, Baden-Wuerttemberg, Germany Grant 32-7545.20/45/1 (Q-AMeLiA).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulgavrikov%2Ftorchconvview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulgavrikov%2Ftorchconvview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulgavrikov%2Ftorchconvview/lists"}