Skip to main content

有用的可视化功能

项目描述

可视化

可视化操作合集,使用更方便,查看使用情况快速上手。

新的功能

2021/09/29

  • 添加pip安装
  • 建立一个更清洁的回购

内容

可视化功能

学习笔记分享

安装

pip install visualize==0.5.1

用法

运行示例

您可以通过克隆此 repo 来尝试example.py以快速开始。

git clone https://github.com/rentainhe/visualization.git
python example.py

结果将保存到./test_grid_attention./test_region_attention

区域注意可视化

将example.jpg下载到您喜欢的任何文件夹

$ wget https://github.com/rentainhe/visualization/blob/master/visualize/test_data/example.jpg

构建以下 python 脚本以快速启动

import numpy as np
from visualize import visualize_region_attention

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 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

请注意,您可以在此处查看区域注意可视化以获取更多详细信息

网格注意力可视化

将example.jpg下载到您喜欢的任何文件夹

$ wget https://github.com/rentainhe/visualization/blob/master/visualize/test_data/example.jpg

构建以下 python 脚本以快速启动

from visualize import visualize_grid_attention_v2
import numpy as np

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: where the image you want to put an attention mask on.
  • save_path: where to save the image.
  • attention_mask: 格式为的attention mask numpy.ndarray,形状为(H, W)
  • save_image=True: 是否保存带有注意力图的图像,例如,默认值:True。
  • save_original_image=True: 同时保存原图,例如,默认:True

请注意,您可以在此处查看注意力图可视化以获取更多详细信息

绘制折线图

构建以下 python 脚本以快速启动

from visualize import draw_line_chart
import numpy as np

# test data
data1 = {"data": [13.15, 14.64, 15.83, 17.99], "name": "data 1"}
data2 = {"data": [14.16, 14.81, 16.11, 18.62], "name": "data 2"}
data_list = []
data_list.append(data1["data"])
data_list.append(data2["data"])
name_list = []
name_list.append(data1["name"])
name_list.append(data2["name"])
draw_line_chart(data_list=data_list,
                labels=name_list,
                xlabel="test_x",
                ylabel="test_y",
                save_path="./test.jpg",
                legend={"loc": "upper left", "frameon": True, "fontsize": 12},
                title="example")
  • data_list:要绘制的数据列表。
  • labels:标签对应data_list中的每一个数据。
  • xlabel: x 轴的标签。
  • ylabel: y 轴的标签。
  • save_path: 保存图片的路径。
  • legend: 传说中的参数。
  • title:保存图像的标题。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

visual-0.5.1.tar.gz (63.5 kB 查看哈希)

已上传 source