{"id":18077562,"url":"https://github.com/rentainhe/visualization","last_synced_at":"2025-04-04T20:05:03.033Z","repository":{"id":41178148,"uuid":"332651065","full_name":"rentainhe/visualization","owner":"rentainhe","description":"a collection of visualization function","archived":false,"fork":false,"pushed_at":"2022-01-15T18:22:25.000Z","size":2955,"stargazers_count":414,"open_issues_count":1,"forks_count":41,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T19:05:37.069Z","etag":null,"topics":["attention","attention-map","attention-mechanism","data-visualization","deep-learning","transformer","vision","vision-mlp","vision-transformer","visualization"],"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/rentainhe.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":"2021-01-25T06:24:58.000Z","updated_at":"2025-03-21T03:38:45.000Z","dependencies_parsed_at":"2022-07-10T16:00:28.683Z","dependency_job_id":null,"html_url":"https://github.com/rentainhe/visualization","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rentainhe%2Fvisualization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rentainhe%2Fvisualization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rentainhe%2Fvisualization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rentainhe%2Fvisualization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rentainhe","download_url":"https://codeload.github.com/rentainhe/visualization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242669,"owners_count":20907133,"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":["attention","attention-map","attention-mechanism","data-visualization","deep-learning","transformer","vision","vision-mlp","vision-transformer","visualization"],"created_at":"2024-10-31T11:45:35.739Z","updated_at":"2025-04-04T20:05:02.975Z","avatar_url":"https://github.com/rentainhe.png","language":"Python","readme":"# visualization\na collection of visualization operation for easier usage, check [usage](#usage) for a quick start.\n\n## New Features\n**2021/10/4**\n- Add `draw_line_chart` function, please check [drawer.py](/visualize/line_chart/drawer.py)\n\n**2021/09/29**\n- Add pip installation\n- Build a cleaner repo\n\n## Contents\n### Visualization Function\n- [__Grid Attention Visualization__](/visualize/grid_attention_visualization/)\n- [__Region Attention Visualization__](/visualize/region_attention_visualization/)\n- [__Draw Line Chart__](/visualize/line_chart/drawer.py)\n\n### Learning Notes Sharing\n- [__Image Reading Difference__](/notes)\n\n### Relative Blogs\n- [Region Attention Map Visualize](https://zhuanlan.zhihu.com/p/364486740)\n- [Grid Attention Map Visualize](https://zhuanlan.zhihu.com/p/356798637)\n\n## Installation\n```bash\npip install visualize==0.5.1\n```\n\n## Usage\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003e Run Example \u003c/b\u003e \u003c/summary\u003e\n\nYou can try [example.py](/example.py) by cloning this repo for a quick start.\n```bash\ngit clone https://github.com/rentainhe/visualization.git\npython example.py\n```\nresults will be saved to `./test_grid_attention` and `./test_region_attention`\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003e Region Attention Visualization \u003c/b\u003e \u003c/summary\u003e\n\n**download the [example.jpg](/visualize/test_data/example.jpg) to any folder you like**\n```bash\n$ wget https://github.com/rentainhe/visualization/blob/master/visualize/test_data/example.jpg\n```\n**build the following python script for a quick start**\n```python\nimport numpy as np\nfrom visualize import visualize_region_attention\n\nimg_path=\"path/to/example.jpg\"\nsave_path=\"example\"\nattention_retio=1.0\nboxes = np.array([[14, 25, 100, 200], [56, 75, 245, 300]], dtype='int')\nboxes_attention = [0.36, 0.64]\nvisualize_region_attention(img_path,\n                           save_path=save_path, \n                           boxes=boxes, \n                           box_attentions=boxes_attention, \n                           attention_ratio=attention_retio,\n                           save_image=True,\n                           save_origin_image=True,\n                           quality=100)\n```\n- `img_path`: where to load the original image\n- `boxes`: a list of coordinates for the bounding boxes\n- `box_attentions`: a list of attention scores for each bounding box\n- `attention_ratio`: a special param, if you set the attention_ratio larger, it will make the attention map look more shallow. Just try!\n- `save_image=True`: save the image with attention map or not, e.g., default: True.\n- `save_original_image=True`: save the original image at the same time, e.g., default: True\n\n**Note that you can check [Region Attention Visualization](/visualize/region_attention_visualization/) here for more details**\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003e Grid Attention Visualization\u003c/b\u003e \u003c/summary\u003e\n\n**download the [example.jpg](/visualize/test_data/example.jpg) to any folder you like**\n```bash\n$ wget https://github.com/rentainhe/visualization/blob/master/visualize/test_data/example.jpg\n```\n\n**build the following python script for a quick start**\n```python\nfrom visualize import visualize_grid_attention_v2\nimport numpy as np\n\nimg_path=\"./example.jpg\"\nsave_path=\"test\"\nattention_mask = np.random.randn(14, 14)\nvisualize_grid_attention_v2(img_path,\n                           save_path=save_path,\n                           attention_mask=attention_mask,\n                           save_image=True,\n                           save_original_image=True,\n                           quality=100)\n```\n- `img_path`: where the image you want to put an attention mask on.\n- `save_path`: where to save the image.\n- `attention_mask`: the attention mask with format `numpy.ndarray`, its shape is (H, W)\n- `save_image=True`: save the image with attention map or not, e.g., default: True.\n- `save_original_image=True`: save the original image at the same time, e.g., default: True\n\n\n**Note that you can check [Grid Attention Visualization](https://github.com/rentainhe/visualization/tree/master/visualize/grid_attention_visualization) here for more details**\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003e Draw Line Chart \u003c/b\u003e \u003c/summary\u003e\n\n**build the following python script for a quick start**\n```python\nfrom visualize import draw_line_chart\n\n# test data\ndata1 = {\"data\": [13.15, 14.64, 15.83, 17.99], \"name\": \"data 1\"}\ndata2 = {\"data\": [14.16, 14.81, 16.11, 18.62], \"name\": \"data 2\"}\ndata_list = []\ndata_list.append(data1[\"data\"])\ndata_list.append(data2[\"data\"])\nname_list = []\nname_list.append(data1[\"name\"])\nname_list.append(data2[\"name\"])\ndraw_line_chart(data_list=data_list,\n                labels=name_list,\n                xlabel=\"test_x\",\n                ylabel=\"test_y\",\n                save_path=\"./test.jpg\",\n                legend={\"loc\": \"upper left\", \"frameon\": True, \"fontsize\": 12},\n                title=\"example\")\n```\n- `data_list`: a list of data to draw.\n- `labels`: the label corresponds to each data in data_list.\n- `xlabel`: label of x-axis.\n- `ylabel`: label of y-axis.\n- `save_path`: the path to save image.\n- `legend`: the params of legend.\n- `title`: the title of the saved image.\n\nYou will get the result like this:\n\n![](figs/line_chart.jpg)\n\n\u003c/details\u003e\n\u003c/details\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frentainhe%2Fvisualization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frentainhe%2Fvisualization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frentainhe%2Fvisualization/lists"}