-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rentainhe/rebuild_project
rebuild project structure
- Loading branch information
Showing
30 changed files
with
354 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Francesco Saverio Zuppichini | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include visualize/test_data/*.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,106 @@ | ||
# visualization | ||
a collection of visualization operation | ||
a collection of visualization operation for easier usage, check [usage](#usage) for a quick start. | ||
|
||
## New Features | ||
**2021/09/29** | ||
- Add pip installation | ||
- Build a cleaner repo | ||
|
||
## Contents | ||
- [__Attention Map Visualization__](https://github.com/rentainhe/visualization/tree/master/visualize_attention_map) | ||
- [__Image Reading Difference__](https://github.com/rentainhe/visualization/tree/master/read_img) | ||
- [__Region Attention Visualization__](https://github.com/rentainhe/visualization/tree/master/visualize_region_attention) | ||
- [__Draw Line Chart__]() | ||
### Visualization Function | ||
- [__Grid Attention Visualization__](/visualize/grid_attention_visualization/) | ||
- [__Region Attention Visualization__](/visualize/region_attention_visualization/) | ||
- [__Draw Line Chart__](/visualize/draw_line_chart/draw.py) | ||
|
||
### Learning Notes Sharing | ||
- [__Image Reading Difference__](/notes) | ||
|
||
|
||
## Installation | ||
```bash | ||
pip install visualize==0.5.0 | ||
``` | ||
|
||
## Usage | ||
### 1. Grid Attention Visualization | ||
<details> | ||
<summary> <b> Run Example </b> </summary> | ||
|
||
You can try [example.py](/example.py) by cloning this repo for a quick start. | ||
```bash | ||
git clone https://github.com/rentainhe/visualization.git | ||
python example.py | ||
``` | ||
results will be saved to `./test_grid_attention` and `./test_region_attention` | ||
</details> | ||
|
||
<details> | ||
<summary> <b> Region Attention Visualization </b> </summary> | ||
|
||
**download the [example.jpg](/visualize/test_data/example.jpg) to any folder you like** | ||
```bash | ||
$ wget | ||
``` | ||
**build the following python script for a quick start** | ||
```python | ||
import numpy as np | ||
from visualize_attention_map.visualize_attention_map_V2 import visulize_attention_ratio | ||
|
||
img_path = 'test_data/test_image.jpg' | ||
save_path = 'test_data/' | ||
random_attention = np.random.randn(14, 14) | ||
from visualize import visualize_region_attention | ||
|
||
visulize_attention_ratio(img_path=img_path, save_path=save_path, attention_mask=random_attention, save_image=True, | ||
save_original_image=True) | ||
img_path="path/to/example.jpg" | ||
save_path="example" | ||
attention_retio=1.0 | ||
boxes = np.array([[14, 25, 100, 200], [56, 75, 245, 300]], dtype='int') | ||
boxes_attention = [0.36, 0.64] | ||
visualize_region_attention(img_path, | ||
save_path=save_path, | ||
boxes=boxes, | ||
box_attentions=boxes_attention, | ||
attention_ratio=attention_retio, | ||
save_image=True, | ||
save_origin_image=True, | ||
quality=100) | ||
``` | ||
- __img_path: where the image you want to put an attention mask on.__ | ||
- __save_path: where to save the image.__ | ||
- __attention_mask: the attention mask with format `numpy.ndarray`, its shape is (H, W)__ | ||
- __save_image=True: save the image with attention map or not, default: True.__ | ||
- __save_original_image=True: save the original image, default: True__ | ||
- `img_path`: where to load the original image | ||
- `boxes`: a list of coordinates for the bounding boxes | ||
- `box_attentions`: a list of attention scores for each bounding box | ||
- `attention_ratio`: a special param, if you set the attention_ratio larger, it will make the attention map look more shallow. Just try! | ||
- `save_image=True`: save the image with attention map or not, e.g., default: True. | ||
- `save_original_image=True`: save the original image at the same time, e.g., default: True | ||
|
||
**Note that you can check [Region Attention Visualization](/visualize/region_attention_visualization/) here for more details** | ||
|
||
__Just run this example to see the result: [grid_attention_example.py](https://github.com/rentainhe/visualization/blob/master/grid_attention_example.py)__ | ||
</details> | ||
|
||
__Or you can check [Attention Map Visualization](https://github.com/rentainhe/visualization/tree/master/visualize_attention_map) here for more details__ | ||
<details> | ||
<summary> <b> Grid Attention Visualization</b> </summary> | ||
|
||
### 2. Region Attention Visualization | ||
**download the [example.jpg](/visualize/test_data/example.jpg) to any folder you like** | ||
```bash | ||
$ wget | ||
``` | ||
|
||
**build the following python script for a quick start** | ||
```python | ||
from visualize_region_attention.region_attention_visualization import region_attention_visualization | ||
from visualize import visualize_grid_attention_v2 | ||
import numpy as np | ||
|
||
img_path = "test_data/test_image.jpg" | ||
boxes = np.array([[14, 25, 100, 200], [56, 75, 245, 300]], dtype='int') | ||
region_attention_visualization(img_path, boxes, box_attentions=[0.36, 0.64], attention_ratio=1.0) | ||
img_path="./example.jpg" | ||
save_path="test" | ||
attention_mask = np.random.randn(14, 14) | ||
visualize_grid_attention_v2(img_path, | ||
save_path=save_path, | ||
attention_mask=attention_mask, | ||
save_image=True, | ||
save_original_image=True, | ||
quality=100) | ||
``` | ||
- __img_path: the path of the original image__ | ||
- __boxes: bounding box__ | ||
- __box_attentions: the attention score of each bounding box__ | ||
- __attention_ratio: a special param, if you set the attention_ratio larger, it will make the attention map look more shallow. Just try!__ | ||
- `img_path`: where the image you want to put an attention mask on. | ||
- `save_path`: where to save the image. | ||
- `attention_mask`: the attention mask with format `numpy.ndarray`, its shape is (H, W) | ||
- `save_image=True`: save the image with attention map or not, e.g., default: True. | ||
- `save_original_image=True`: save the original image at the same time, e.g., default: True | ||
|
||
|
||
__Just run this example to see the result: [region_attention_example.py](https://github.com/rentainhe/visualization/blob/master/region_attention_example.py)__ | ||
**Note that you can check [Attention Map Visualization](https://github.com/rentainhe/visualization/tree/master/visualize_attention_map) here for more details** | ||
|
||
__Or you can check [Region Attention Visualization](https://github.com/rentainhe/visualization/tree/master/visualize_region_attention) here for more details__ | ||
</details> | ||
|
||
### 3. Draw Line Chart | ||
- [__example.py__](https://github.com/rentainhe/visualization/blob/master/draw_line_chart/draw.py) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from visualize import visualize_region_attention, visualize_grid_attention, visualize_grid_attention_v2 | ||
import numpy as np | ||
|
||
def run_region_attention_example(): | ||
# test region attention | ||
img_path="visualize/test_data/example.jpg" | ||
save_path="test_region_attention/" | ||
attention_retio=1.0 | ||
boxes = np.array([[14, 25, 100, 200], [56, 75, 245, 300]], dtype='int') | ||
boxes_attention = [0.36, 0.64] | ||
visualize_region_attention(img_path, | ||
save_path=save_path, | ||
boxes=boxes, | ||
box_attentions=boxes_attention, | ||
attention_ratio=attention_retio, | ||
save_image=True, | ||
save_origin_image=True, | ||
quality=100) | ||
|
||
|
||
def run_grid_attention_example(img_path="visualize/test_data/example.jpg", save_path="test_grid_attention/", attention_mask=None, version=2, quality=100): | ||
if not attention_mask: | ||
attention_mask = np.random.randn(14, 14) | ||
assert version in [1, 2], "We only support two version of attention visualization example" | ||
if version == 1: | ||
visualize_grid_attention(img_path=img_path, | ||
save_path=save_path, | ||
attention_mask=attention_mask, | ||
save_image=True, | ||
save_original_image=True, | ||
quality=quality) | ||
elif version == 2: | ||
visualize_grid_attention_v2(img_path=img_path, | ||
save_path=save_path, | ||
attention_mask=attention_mask, | ||
save_image=True, | ||
save_original_image=True, | ||
quality=quality) | ||
|
||
if __name__ == "__main__": | ||
run_grid_attention_example(version=2) # version in [1, 2] | ||
run_region_attention_example() |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from setuptools import find_packages | ||
|
||
|
||
try: | ||
from setuptools import setup | ||
except ImportError: | ||
from distutils.core import setup | ||
""" | ||
这里这么写的目的是防止setup导入出错,安装出现异常。但一般不会出错 | ||
""" | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name='visualize', | ||
version='0.1.43', # 版本号 | ||
author='rentianhe', | ||
author_email='[email protected]', | ||
description='useful visualization function', | ||
license='MIT', | ||
packages=find_packages(),#需要安装的代码包,也可以用find_packages函数 | ||
install_requires=['numpy', | ||
'opencv-python', | ||
'matplotlib', | ||
'Pillow' | ||
], | ||
classifiers = [ | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Intended Audience :: Developers', | ||
'Operating System :: OS Independent', | ||
], | ||
keywords='computer vision', | ||
url='https://github.com/rentainhe/visualization', | ||
# zip_safe=True, # 设为True,以zip的方式进行传输 | ||
# include_package_data=True, | ||
platforms='any', | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .grid_attention_visualization import visualize_grid_attention, visualize_grid_attention_v2 | ||
from .region_attention_visualization import visualize_region_attention |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .grid_attention_example import run_grid_attention_example | ||
from .region_attention_example import run_region_attention_example |
Oops, something went wrong.