未验证 提交 7fed2024 编写于 作者: 走神的阿圆's avatar 走神的阿圆 提交者: GitHub

Add visualdl. (#745)

Add image for visualdl board.
上级 50bc85d2
...@@ -41,8 +41,8 @@ list below can be viewed by `--help` ...@@ -41,8 +41,8 @@ list below can be viewed by `--help`
| --draw_threshold | infer | Threshold to reserve the result for visualization | 0.5 | `--draw_threshold 0.7` | | --draw_threshold | infer | Threshold to reserve the result for visualization | 0.5 | `--draw_threshold 0.7` |
| --infer_dir | infer | Directory for images to perform inference on | None | | | --infer_dir | infer | Directory for images to perform inference on | None | |
| --infer_img | infer | Image path | None | higher priority over --infer_dir | | --infer_img | infer | Image path | None | higher priority over --infer_dir |
| --use_tb | train/infer | Whether to record the data with [tb-paddle](https://github.com/linshuliang/tb-paddle), so as to display in Tensorboard | False | | | --use_vdl | train/infer | Whether to record the data with [VisualDL](https://github.com/paddlepaddle/visualdl), so as to display in VisualDL | False | |
| --tb\_log_dir | train/infer | tb-paddle logging directory for image | train:`tb_log_dir/scalar` infer: `tb_log_dir/image` | | | --vdl\_log_dir | train/infer | VisualDL logging directory for image | train:`vdl_log_dir/scalar` infer: `vdl_log_dir/image` | |
## Examples ## Examples
...@@ -163,7 +163,7 @@ moment, but it is a planned feature ...@@ -163,7 +163,7 @@ moment, but it is a planned feature
--output_dir=infer_output/ \ --output_dir=infer_output/ \
--draw_threshold=0.5 \ --draw_threshold=0.5 \
-o weights=output/faster_rcnn_r50_1x/model_final \ -o weights=output/faster_rcnn_r50_1x/model_final \
--use_tb=Ture --use_vdl=Ture
``` ```
`--draw_threshold` is an optional argument. Default is 0.5. `--draw_threshold` is an optional argument. Default is 0.5.
......
...@@ -38,8 +38,8 @@ python tools/infer.py -c configs/faster_rcnn_r50_1x.yml --infer_img=demo/0000005 ...@@ -38,8 +38,8 @@ python tools/infer.py -c configs/faster_rcnn_r50_1x.yml --infer_img=demo/0000005
| --draw_threshold | infer | 可视化时分数阈值 | 0.5 | `--draw_threshold 0.7` | | --draw_threshold | infer | 可视化时分数阈值 | 0.5 | `--draw_threshold 0.7` |
| --infer_dir | infer | 用于预测的图片文件夹路径 | None | | | --infer_dir | infer | 用于预测的图片文件夹路径 | None | |
| --infer_img | infer | 用于预测的图片路径 | None | 相较于`--infer_dir`具有更高优先级 | | --infer_img | infer | 用于预测的图片路径 | None | 相较于`--infer_dir`具有更高优先级 |
| --use_tb | train/infer | 是否使用[tb-paddle](https://github.com/linshuliang/tb-paddle)记录数据,进而在TensorBoard中显示 | False | | | --use_vdl | train/infer | 是否使用[VisualDL](https://github.com/paddlepaddle/visualdl)记录数据,进而在VisualDL面板中显示 | False | |
| --tb\_log_dir | train/infer | 指定 tb-paddle 记录数据的存储路径 | train:`tb_log_dir/scalar` infer: `tb_log_dir/image` | | | --vdl\_log_dir | train/infer | 指定 VisualDL 记录数据的存储路径 | train:`vdl_log_dir/scalar` infer: `vdl_log_dir/image` | |
## 使用示例 ## 使用示例
......
...@@ -22,20 +22,20 @@ Training: ...@@ -22,20 +22,20 @@ Training:
```bash ```bash
python -u tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml \ python -u tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml \
--use_tb=True \ --use_vdl=True \
--tb_log_dir=tb_fruit_dir/scalar \ --vdl_log_dir=vdl_fruit_dir/scalar \
--eval --eval
``` ```
Use `yolov3_mobilenet_v1` to fine-tune the model from COCO dataset. Meanwhile, loss and mAP can be observed on tensorboard. Use `yolov3_mobilenet_v1` to fine-tune the model from COCO dataset. Meanwhile, loss and mAP can be observed on VisualDL.
```bash ```bash
tensorboard --logdir tb_fruit_dir/scalar/ --host <host_IP> --port <port_num> visualdl --logdir vdl_fruit_dir/scalar/ --host <host_IP> --port <port_num>
``` ```
Result on tensorboard is shown below: Result on VisualDL is shown below:
![tensorboard_fruit.jpg](../images/tensorboard_fruit.jpg) ![visualdl_fruit.jpg](../images/visualdl_fruit.jpg)
Model can be downloaded [here](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_fruit.tar) Model can be downloaded [here](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_fruit.tar)
......
...@@ -24,21 +24,21 @@ python dataset/fruit/download_fruit.py ...@@ -24,21 +24,21 @@ python dataset/fruit/download_fruit.py
```bash ```bash
python -u tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml \ python -u tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml \
--use_tb=True \ --use_vdl=True \
--tb_log_dir=tb_fruit_dir/scalar \ --vdl_log_dir=vdl_fruit_dir/scalar \
--eval --eval
``` ```
训练使用`yolov3_mobilenet_v1`基于COCO数据集训练好的模型进行finetune。训练期间可以通过tensorboard实时观察loss和精度值,启动命令如下: 训练使用`yolov3_mobilenet_v1`基于COCO数据集训练好的模型进行finetune。训练期间可以通过VisualDL实时观察loss和精度值,启动命令如下:
```bash ```bash
tensorboard --logdir tb_fruit_dir/scalar/ --host <host_IP> --port <port_num> visualdl --logdir vdl_fruit_dir/scalar/ --host <host_IP> --port <port_num>
``` ```
tensorboard结果显示如下: VisualDL结果显示如下:
![](../images/tensorboard_fruit.jpg) ![](../images/visualdl_fruit.jpg)
训练模型[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_fruit.tar) 训练模型[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_fruit.tar)
......
tqdm tqdm
docstring_parser @ http://github.com/willthefrog/docstring_parser/tarball/master docstring_parser @ http://github.com/willthefrog/docstring_parser/tarball/master
typeguard ; python_version >= '3.4' typeguard ; python_version >= '3.4'
tb-paddle visualdl>=2.0.0b
tensorboard >= 1.15
opencv-python opencv-python
PyYAML PyYAML
shapely shapely
...@@ -244,12 +244,12 @@ def main(): ...@@ -244,12 +244,12 @@ def main():
time_stat = deque(maxlen=cfg.log_smooth_window) time_stat = deque(maxlen=cfg.log_smooth_window)
best_box_ap_list = [0.0, 0] #[map, iter] best_box_ap_list = [0.0, 0] #[map, iter]
# use tb-paddle to log data # use VisualDL to log data
if FLAGS.use_tb: if FLAGS.use_vdl:
from tb_paddle import SummaryWriter from visualdl import LogWriter
tb_writer = SummaryWriter(FLAGS.tb_log_dir) vdl_writer = LogWriter(FLAGS.vdl_log_dir)
tb_loss_step = 0 vdl_loss_step = 0
tb_mAP_step = 0 vdl_mAP_step = 0
if FLAGS.eval: if FLAGS.eval:
resolution = None resolution = None
...@@ -286,12 +286,12 @@ def main(): ...@@ -286,12 +286,12 @@ def main():
outs = exe.run(compiled_train_prog, fetch_list=train_values) outs = exe.run(compiled_train_prog, fetch_list=train_values)
stats = {k: np.array(v).mean() for k, v in zip(train_keys, outs[:-1])} stats = {k: np.array(v).mean() for k, v in zip(train_keys, outs[:-1])}
# use tb-paddle to log loss # use VisualDL to log loss
if FLAGS.use_tb: if FLAGS.use_vdl:
if it % cfg.log_iter == 0: if it % cfg.log_iter == 0:
for loss_name, loss_value in stats.items(): for loss_name, loss_value in stats.items():
tb_writer.add_scalar(loss_name, loss_value, tb_loss_step) vdl_writer.add_scalar(loss_name, loss_value, vdl_loss_step)
tb_loss_step += 1 vdl_loss_step += 1
train_stats.update(stats) train_stats.update(stats)
logs = train_stats.log() logs = train_stats.log()
...@@ -329,10 +329,10 @@ def main(): ...@@ -329,10 +329,10 @@ def main():
map_type, map_type,
dataset=dataset) dataset=dataset)
# use tb_paddle to log mAP # use VisualDL to log mAP
if FLAGS.use_tb: if FLAGS.use_vdl:
tb_writer.add_scalar("mAP", box_ap_stats[0], tb_mAP_step) vdl_writer.add_scalar("mAP", box_ap_stats[0], vdl_mAP_step)
tb_mAP_step += 1 vdl_mAP_step += 1
if box_ap_stats[0] > best_box_ap_list[0]: if box_ap_stats[0] > best_box_ap_list[0]:
best_box_ap_list[0] = box_ap_stats[0] best_box_ap_list[0] = box_ap_stats[0]
...@@ -374,15 +374,15 @@ if __name__ == '__main__': ...@@ -374,15 +374,15 @@ if __name__ == '__main__':
type=str, type=str,
help="Evaluation directory, default is current directory.") help="Evaluation directory, default is current directory.")
parser.add_argument( parser.add_argument(
"--use_tb", "--use_vdl",
type=bool, type=bool,
default=False, default=False,
help="whether to record the data to Tensorboard.") help="whether to record the data to VisualDL.")
parser.add_argument( parser.add_argument(
'--tb_log_dir', '--vdl_log_dir',
type=str, type=str,
default="tb_log_dir/scalar", default="vdl_log_dir/scalar",
help='Tensorboard logging directory for scalar.') help='VisualDL logging directory for scalar.')
parser.add_argument( parser.add_argument(
"-p", "-p",
......
...@@ -158,12 +158,12 @@ def main(): ...@@ -158,12 +158,12 @@ def main():
callable(model.is_bbox_normalized): callable(model.is_bbox_normalized):
is_bbox_normalized = model.is_bbox_normalized() is_bbox_normalized = model.is_bbox_normalized()
# use tb-paddle to log image # use VisualDL to log image
if FLAGS.use_tb: if FLAGS.use_vdl:
from tb_paddle import SummaryWriter from visualdl import LogWriter
tb_writer = SummaryWriter(FLAGS.tb_log_dir) vdl_writer = LogWriter(FLAGS.vdl_log_dir)
tb_image_step = 0 vdl_image_step = 0
tb_image_frame = 0 # each frame can display ten pictures at most. vdl_image_frame = 0 # each frame can display ten pictures at most.
imid2path = dataset.get_imid2path() imid2path = dataset.get_imid2path()
for iter_id, data in enumerate(loader()): for iter_id, data in enumerate(loader()):
...@@ -191,32 +191,27 @@ def main(): ...@@ -191,32 +191,27 @@ def main():
image_path = imid2path[int(im_id)] image_path = imid2path[int(im_id)]
image = Image.open(image_path).convert('RGB') image = Image.open(image_path).convert('RGB')
# use tb-paddle to log original image # use VisualDL to log original image
if FLAGS.use_tb: if FLAGS.use_vdl:
original_image_np = np.array(image) original_image_np = np.array(image)
tb_writer.add_image( vdl_writer.add_image(
"original/frame_{}".format(tb_image_frame), "original/frame_{}".format(vdl_image_frame),
original_image_np, original_image_np, vdl_image_step)
tb_image_step,
dataformats='HWC')
image = visualize_results(image, image = visualize_results(image,
int(im_id), catid2name, int(im_id), catid2name,
FLAGS.draw_threshold, bbox_results, FLAGS.draw_threshold, bbox_results,
mask_results) mask_results)
# use tb-paddle to log image with bbox # use VisualDL to log image with bbox
if FLAGS.use_tb: if FLAGS.use_vdl:
infer_image_np = np.array(image) infer_image_np = np.array(image)
tb_writer.add_image( vdl_writer.add_image("bbox/frame_{}".format(vdl_image_frame),
"bbox/frame_{}".format(tb_image_frame), infer_image_np, vdl_image_step)
infer_image_np, vdl_image_step += 1
tb_image_step, if vdl_image_step % 10 == 0:
dataformats='HWC') vdl_image_step = 0
tb_image_step += 1 vdl_image_frame += 1
if tb_image_step % 10 == 0:
tb_image_step = 0
tb_image_frame += 1
save_name = get_save_image_name(FLAGS.output_dir, image_path) save_name = get_save_image_name(FLAGS.output_dir, image_path)
logger.info("Detection bbox results save in {}".format(save_name)) logger.info("Detection bbox results save in {}".format(save_name))
...@@ -246,14 +241,14 @@ if __name__ == '__main__': ...@@ -246,14 +241,14 @@ if __name__ == '__main__':
default=0.5, default=0.5,
help="Threshold to reserve the result for visualization.") help="Threshold to reserve the result for visualization.")
parser.add_argument( parser.add_argument(
"--use_tb", "--use_vdl",
type=bool, type=bool,
default=False, default=False,
help="whether to record the data to Tensorboard.") help="whether to record the data to VisualDL.")
parser.add_argument( parser.add_argument(
'--tb_log_dir', '--vdl_log_dir',
type=str, type=str,
default="tb_log_dir/image", default="vdl_log_dir/image",
help='Tensorboard logging directory for image.') help='VisualDL logging directory for image.')
FLAGS = parser.parse_args() FLAGS = parser.parse_args()
main() main()
...@@ -222,12 +222,12 @@ def main(): ...@@ -222,12 +222,12 @@ def main():
time_stat = deque(maxlen=cfg.log_smooth_window) time_stat = deque(maxlen=cfg.log_smooth_window)
best_box_ap_list = [0.0, 0] #[map, iter] best_box_ap_list = [0.0, 0] #[map, iter]
# use tb-paddle to log data # use VisualDL to log data
if FLAGS.use_tb: if FLAGS.use_vdl:
from tb_paddle import SummaryWriter from visualdl import LogWriter
tb_writer = SummaryWriter(FLAGS.tb_log_dir) vdl_writer = LogWriter(FLAGS.vdl_log_dir)
tb_loss_step = 0 vdl_loss_step = 0
tb_mAP_step = 0 vdl_mAP_step = 0
for it in range(start_iter, cfg.max_iters): for it in range(start_iter, cfg.max_iters):
start_time = end_time start_time = end_time
...@@ -239,12 +239,12 @@ def main(): ...@@ -239,12 +239,12 @@ def main():
outs = exe.run(compiled_train_prog, fetch_list=train_values) outs = exe.run(compiled_train_prog, fetch_list=train_values)
stats = {k: np.array(v).mean() for k, v in zip(train_keys, outs[:-1])} stats = {k: np.array(v).mean() for k, v in zip(train_keys, outs[:-1])}
# use tb-paddle to log loss # use vdl-paddle to log loss
if FLAGS.use_tb: if FLAGS.use_vdl:
if it % cfg.log_iter == 0: if it % cfg.log_iter == 0:
for loss_name, loss_value in stats.items(): for loss_name, loss_value in stats.items():
tb_writer.add_scalar(loss_name, loss_value, tb_loss_step) vdl_writer.add_scalar(loss_name, loss_value, vdl_loss_step)
tb_loss_step += 1 vdl_loss_step += 1
train_stats.update(stats) train_stats.update(stats)
logs = train_stats.log() logs = train_stats.log()
...@@ -287,10 +287,10 @@ def main(): ...@@ -287,10 +287,10 @@ def main():
is_bbox_normalized, FLAGS.output_eval, map_type, is_bbox_normalized, FLAGS.output_eval, map_type,
cfg['EvalReader']['dataset']) cfg['EvalReader']['dataset'])
# use tb_paddle to log mAP # use vdl_paddle to log mAP
if FLAGS.use_tb: if FLAGS.use_vdl:
tb_writer.add_scalar("mAP", box_ap_stats[0], tb_mAP_step) vdl_writer.add_scalar("mAP", box_ap_stats[0], vdl_mAP_step)
tb_mAP_step += 1 vdl_mAP_step += 1
if box_ap_stats[0] > best_box_ap_list[0]: if box_ap_stats[0] > best_box_ap_list[0]:
best_box_ap_list[0] = box_ap_stats[0] best_box_ap_list[0] = box_ap_stats[0]
...@@ -335,15 +335,15 @@ if __name__ == '__main__': ...@@ -335,15 +335,15 @@ if __name__ == '__main__':
type=str, type=str,
help="Evaluation directory, default is current directory.") help="Evaluation directory, default is current directory.")
parser.add_argument( parser.add_argument(
"--use_tb", "--use_vdl",
type=bool, type=bool,
default=False, default=False,
help="whether to record the data to Tensorboard.") help="whether to record the data to VisualDL.")
parser.add_argument( parser.add_argument(
'--tb_log_dir', '--vdl_log_dir',
type=str, type=str,
default="tb_log_dir/scalar", default="vdl_log_dir/scalar",
help='Tensorboard logging directory for scalar.') help='VisualDL logging directory for scalar.')
parser.add_argument( parser.add_argument(
"--enable_ce", "--enable_ce",
type=bool, type=bool,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册