diff --git a/demo/components/image_matrix_test.py b/demo/components/image_matrix_test.py new file mode 100644 index 0000000000000000000000000000000000000000..496542a8a189b92710986bf33f5f42e0998eba6f --- /dev/null +++ b/demo/components/image_matrix_test.py @@ -0,0 +1,53 @@ +# Copyright (c) 2021 VisualDL Authors. All Rights Reserve. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ======================================================================= + +# coding=utf-8 + +import numpy as np +from PIL import Image +from visualdl import LogWriter + + +def random_crop(img): + """Get random block of img, which size is 100x100. + """ + img = Image.open(img) + w, h = img.size + random_w = np.random.randint(0, w - 100) + random_h = np.random.randint(0, h - 100) + r = img.crop((random_w, random_h, random_w + 100, random_h + 100)) + return np.asarray(r) + + +if __name__ == '__main__': + imgs = [] + # 获取8张图像 + for step in range(8): + img = random_crop("../../docs/images/dog.jpg") + imgs.append(img) + imgs = np.array(imgs) + + with LogWriter(logdir='./log/image_matrix_test/train') as writer: + writer.add_image(tag='doges', step=0, img=imgs[0]) + # 合成长宽尽量接近的图形矩阵,本例生成3X3的矩阵 + writer.add_image_matrix(tag='doges', step=1, imgs=imgs, rows=-1) + # 合成长为1的图形矩阵,本例生成1x8的矩阵 + writer.add_image_matrix(tag='doges', step=2, scale=10, imgs=imgs, rows=1) + # 合成长为2的图形矩阵,本例生成2X4的矩阵 + writer.add_image_matrix(tag='doges', step=3, scale=10, imgs=imgs, rows=2) + # 合成长为3的图形矩阵,本例生成3X3的矩阵 + writer.add_image_matrix(tag='doges', step=4, imgs=imgs, rows=3) + # 合成长为4的图形矩阵,本例生成4X2的矩阵 + writer.add_image_matrix(tag='doges', step=5, imgs=imgs, rows=4) diff --git a/demo/components/test.sh b/demo/components/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..095bab9bde0d808d8bb4a8e253111b8be2509d46 --- /dev/null +++ b/demo/components/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +python scalar_test.py +python image_test.py +python image_matrix_test.py +python histogram_test.py +python high_dimensional_test.py +python audio_test.py +python text_test.py +python pr_curve_test.py +python roc_curve_test.py + diff --git a/demo/components/text_test.py b/demo/components/text_test.py new file mode 100644 index 0000000000000000000000000000000000000000..12a731fc359969c5696c6e40c858e691257a4c31 --- /dev/null +++ b/demo/components/text_test.py @@ -0,0 +1,31 @@ +# Copyright (c) 2021 VisualDL Authors. All Rights Reserve. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ======================================================================= + +# coding=utf-8 + +from visualdl import LogWriter + +if __name__ == '__main__': + texts = [ + '上联: 众 佛 群 灵 光 圣 地 下联: 众 生 一 念 证 菩 提', + '上联: 乡 愁 何 处 解 下联: 故 事 几 时 休', + '上联: 清 池 荷 试 墨 下联: 碧 水 柳 含 情', + '上联: 既 近 浅 流 安 笔 砚 下联: 欲 将 直 气 定 乾 坤', + '上联: 日 丽 萱 闱 祝 无 量 寿 下联: 月 明 桂 殿 祝 有 余 龄', + '上联: 一 地 残 红 风 拾 起 下联: 半 窗 疏 影 月 窥 来' + ] + with LogWriter(logdir="./log/text_test/train") as writer: + for step in range(len(texts)): + writer.add_text(tag="output", step=step, text_string=texts[step]) diff --git a/docs/components/README.md b/docs/components/README.md index 05a45629c82d621bb5faf788ff2d1456fa7d9cf6..a30b37dd2bdf590585a14049b7b450fd53632aba 100644 --- a/docs/components/README.md +++ b/docs/components/README.md @@ -13,12 +13,14 @@ VisualDL 是一个面向深度学习任务设计的可视化工具。VisualDL | [ Scalar](#Scalar--标量组件) | 折线图 | 动态展示损失函数值、准确率等标量数据 | | [Image](#Image--图片可视化组件) | 图片可视化 | 显示图片,可显示输入图片和处理后的结果,便于查看中间过程的变化 | | [Audio](#Audio--音频播放组件) | 音频可视化 | 播放训练过程中的音频数据,监控语音识别与合成等任务的训练过程 | +| [Text](#Text--文本组件) | 文本可视化 | 展示文本任务任意阶段的数据输出,对比不同阶段的文本变化,便于深入了解训练过程及效果。 | | [Graph](#Graph--网络结构组件) | 网络结构 | 展示网络结构、节点属性及数据流向,辅助学习、优化网络结构 | | [Histogram](#Histogram--直方图组件) | 直方图 | 展示训练过程中权重、梯度等张量的分布 | | [PR Curve](#PR-Curve--PR曲线组件) | 折线图 | 权衡精度与召回率之间的平衡关系 | | [ROC Curve](#ROC-Curve--ROC曲线组件) | 折线图 | 展示不同阈值下的模型表现 | | [High Dimensional](#High-Dimensional--数据降维组件) | 数据降维 | 将高维数据映射到 2D/3D 空间来可视化嵌入,便于观察不同数据的相关性 | + 同时,VisualDL提供可视化结果保存服务,通过 [VDL.service](#vdlservice) 生成链接,保存并分享可视化结果 ## Scalar--标量组件 @@ -305,6 +307,8 @@ add_image_matrix(tag, imgs, step, rows=-1, scale=1, walltime=None, dataformats=" | walltime | int | 记录数据的时间戳,默认为当前时间戳 | | dataformats| string | 传入的图片格式,包括`NCHW`、`HWC`、`HW`,默认为`HWC`| +**PS:当给定的子图像数量不足时,将用空白图像填充,以保证生成的图形为完整矩形** + #### Demo 下面展示了使用 Image 组件合成并记录多张图片数据的示例,代码文件请见[Image组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/image_matrix_test.py) ```python @@ -438,6 +442,80 @@ visualdl --logdir ./log --port 8080

+## Text--文本组件 + +### 介绍 + +Text展示文本任务任意阶段的数据输出,对比不同阶段的文本变化,便于深入了解训练过程及效果。 + +### 记录接口 + +Text组件的记录接口如下: + +```python +add_text(self, tag, text_string, step=None, walltime=None) +``` + +接口参数说明如下: + +| 参数 | 格式 | 含义 | +| -------------- | --------------------- | ------------------------------------------- | +| tag | string | 记录指标的标志,如`train/loss`,不能含有`%` | +| text_string | string | 文本字符串 | +| step | int | 记录的步数 | +| walltime | int | 记录数据的时间戳,默认为当前时间戳 | + +### Demo + +下面展示了使用 Text 组件记录数据的示例,代码见[Text组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/text_test.py) + +```python +from visualdl import LogWriter +if __name__ == '__main__': + texts = [ + '上联: 众 佛 群 灵 光 圣 地 下联: 众 生 一 念 证 菩 提', + '上联: 乡 愁 何 处 解 下联: 故 事 几 时 休', + '上联: 清 池 荷 试 墨 下联: 碧 水 柳 含 情', + '上联: 既 近 浅 流 安 笔 砚 下联: 欲 将 直 气 定 乾 坤', + '上联: 日 丽 萱 闱 祝 无 量 寿 下联: 月 明 桂 殿 祝 有 余 龄', + '上联: 一 地 残 红 风 拾 起 下联: 半 窗 疏 影 月 窥 来' + ] + with LogWriter(logdir="./log/text_test/train") as writer: + for step in range(len(texts)): + writer.add_text(tag="output", step=step, text_string=texts[step]) +``` + +运行上述程序后,在命令行执行 + +```shell +visualdl --logdir ./log --port 8080 +``` + +接着在浏览器打开`http://127.0.0.1:8080`,即可查看Text + +

+ +

+ +### 功能操作说明 + +- 可搜索文本标签显示对应文本数据 + +

+ +

+ +- 可搜索数据流标签显示对应数据流数据 + +

+ +

+ +- 可折叠标签 + +

+ +

## Graph--网络结构组件 @@ -880,7 +958,6 @@ visualdl --logdir ./log --port 8080

- ## VDL.service ### 简介 diff --git a/docs/components/UserGuide-en.md b/docs/components/UserGuide-en.md index 5f1001302b7f4a6a2a354794beb98bec6b632210..bd873ed5da41ec0ece35bb7f950adaeeba418717 100644 --- a/docs/components/UserGuide-en.md +++ b/docs/components/UserGuide-en.md @@ -16,6 +16,7 @@ Currently, VisualDL provides seven components: scalar, image, audio, graph, hist | [ Scalar](#Scalar--Line-Chart) | Line Chart | Display scalar data such as loss and accuracy dynamically. | | [Image](#Image--Image-Visualization) | Image Visualization | Display images, visualizing the input and the output and making it easy to view the changes in the intermediate process. | | [Audio](#Audio--Audio-Play) | Audio Play | Play the audio during the training process, making it easy to monitor the process of speech recognition and text-to-speech. | +| [Text](#Text) | Text Visualization | Visualizes the text output of NLP models within any stage, aiding developers to compare the changes of outputs so as to deeply understand the training process and simply evaluate the performance of the model. | | [Graph](#Graph--Network-Structure) | Network Structure | Visualize network structures, node attributes and data flow, assisting developers to learn and to optimize network structures. | | [Histogram](#Histogram--Distribution-of-Tensors) | Distribution of Tensors | Present the changes of distributions of tensors, such as weights/gradients/bias, during the training process. | | [PR Curve](#PR-Curve) | Precision & Recall Curve | Display precision-recall curves across training steps, clarifying the tradeoff between precision and recall when comparing models. | @@ -370,6 +371,81 @@ Then, open the browser and enter the address: `http://127.0.0.1:8080`to view:

+## Text + +### Introduction + +visualizes the text output of NLP models within any stage, aiding developers to compare the changes of outputs so as to deeply understand the training process and simply evaluate the performance of the model. + +### Record Interface + +The interface of the Text is shown as follows: + +```python +add_text(self, tag, text_string, step=None, walltime=None) +``` + +The interface parameters are described as follows: + +| parameter | format | meaning | +| -------------- | --------------------- | ------------------------------------------- | +| tag | string | Record the name of the text data,e.g.train/loss. Notice that the name cannot contain `%` | +| text_string | string | Value of text | +| step | int | Record the training steps | +| walltime | int | Record the time-stamp of the data, and the default is the current time-stamp | + +### Demo + +The following shows an example of how to use Text component, and script can be found in [Text Demo](../../demo/components/text_test.py) + +```python +from visualdl import LogWriter +if __name__ == '__main__': + texts = [ + '上联: 众 佛 群 灵 光 圣 地 下联: 众 生 一 念 证 菩 提', + '上联: 乡 愁 何 处 解 下联: 故 事 几 时 休', + '上联: 清 池 荷 试 墨 下联: 碧 水 柳 含 情', + '上联: 既 近 浅 流 安 笔 砚 下联: 欲 将 直 气 定 乾 坤', + '上联: 日 丽 萱 闱 祝 无 量 寿 下联: 月 明 桂 殿 祝 有 余 龄', + '上联: 一 地 残 红 风 拾 起 下联: 半 窗 疏 影 月 窥 来' + ] + with LogWriter(logdir="./log/text_test/train") as writer: + for step in range(len(texts)): + writer.add_text(tag="output", step=step, text_string=texts[step]) +``` + +After running the above program, developers can launch the panel by: + +```shell +visualdl --logdir ./log --port 8080 +``` + +Then, open the browser and enter the address`http://127.0.0.1:8080` to view: + +

+ +

+ +### Functional Instrucions + +- Developers can find the target text by searching corresponded tags. + +

+ +

+ +- Developers can find the target runs by searching corresponded tags. + +

+ +

+ +- Developers can fold the tab of text. + +

+ +

+ ## Graph--Network Structure