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

Add visualdl. (#800)

Add image for visualdl board.
上级 cb0ce1f5
......@@ -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` |
| --infer_dir | infer | Directory for images to perform inference on | None | |
| --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 | |
| --tb\_log_dir | train/infer | tb-paddle logging directory for image | train:`tb_log_dir/scalar` infer: `tb_log_dir/image` | |
| --use_vdl | train/infer | Whether to record the data with [VisualDL](https://github.com/paddlepaddle/visualdl), so as to display in VisualDL | False | |
| --vdl\_log_dir | train/infer | VisualDL logging directory for image | train:`vdl_log_dir/scalar` infer: `vdl_log_dir/image` | |
## Examples
......@@ -163,7 +163,7 @@ moment, but it is a planned feature
--output_dir=infer_output/ \
--draw_threshold=0.5 \
-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.
......
......@@ -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` |
| --infer_dir | infer | 用于预测的图片文件夹路径 | None | |
| --infer_img | infer | 用于预测的图片路径 | None | 相较于`--infer_dir`具有更高优先级 |
| --use_tb | train/infer | 是否使用[tb-paddle](https://github.com/linshuliang/tb-paddle)记录数据,进而在TensorBoard中显示 | False | |
| --tb\_log_dir | train/infer | 指定 tb-paddle 记录数据的存储路径 | train:`tb_log_dir/scalar` infer: `tb_log_dir/image` | |
| --use_vdl | train/infer | 是否使用[VisualDL](https://github.com/paddlepaddle/visualdl)记录数据,进而在VisualDL面板中显示 | False | |
| --vdl\_log_dir | train/infer | 指定 VisualDL 记录数据的存储路径 | train:`vdl_log_dir/scalar` infer: `vdl_log_dir/image` | |
## 使用示例
......
......@@ -22,20 +22,20 @@ Training:
```bash
python -u tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml \
--use_tb=True \
--tb_log_dir=tb_fruit_dir/scalar \
--use_vdl=True \
--vdl_log_dir=vdl_fruit_dir/scalar \
--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
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)
......
......@@ -24,21 +24,21 @@ python dataset/fruit/download_fruit.py
```bash
python -u tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml \
--use_tb=True \
--tb_log_dir=tb_fruit_dir/scalar \
--use_vdl=True \
--vdl_log_dir=vdl_fruit_dir/scalar \
--eval
```
训练使用`yolov3_mobilenet_v1`基于COCO数据集训练好的模型进行finetune。训练期间可以通过tensorboard实时观察loss和精度值,启动命令如下:
训练使用`yolov3_mobilenet_v1`基于COCO数据集训练好的模型进行finetune。训练期间可以通过VisualDL实时观察loss和精度值,启动命令如下:
```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)
......
......@@ -244,12 +244,12 @@ def main():
time_stat = deque(maxlen=cfg.log_smooth_window)
best_box_ap_list = [0.0, 0] #[map, iter]
# use tb-paddle to log data
if FLAGS.use_tb:
from tb_paddle import SummaryWriter
tb_writer = SummaryWriter(FLAGS.tb_log_dir)
tb_loss_step = 0
tb_mAP_step = 0
# use VisualDL to log data
if FLAGS.use_vdl:
from visualdl import LogWriter
vdl_writer = LogWriter(FLAGS.vdl_log_dir)
vdl_loss_step = 0
vdl_mAP_step = 0
if FLAGS.eval:
resolution = None
......@@ -286,12 +286,12 @@ def main():
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])}
# use tb-paddle to log loss
if FLAGS.use_tb:
# use VisualDL to log loss
if FLAGS.use_vdl:
if it % cfg.log_iter == 0:
for loss_name, loss_value in stats.items():
tb_writer.add_scalar(loss_name, loss_value, tb_loss_step)
tb_loss_step += 1
vdl_writer.add_scalar(loss_name, loss_value, vdl_loss_step)
vdl_loss_step += 1
train_stats.update(stats)
logs = train_stats.log()
......@@ -329,10 +329,10 @@ def main():
map_type,
dataset=dataset)
# use tb_paddle to log mAP
if FLAGS.use_tb:
tb_writer.add_scalar("mAP", box_ap_stats[0], tb_mAP_step)
tb_mAP_step += 1
# use VisualDL to log mAP
if FLAGS.use_vdl:
vdl_writer.add_scalar("mAP", box_ap_stats[0], vdl_mAP_step)
vdl_mAP_step += 1
if box_ap_stats[0] > best_box_ap_list[0]:
best_box_ap_list[0] = box_ap_stats[0]
......@@ -374,15 +374,15 @@ if __name__ == '__main__':
type=str,
help="Evaluation directory, default is current directory.")
parser.add_argument(
"--use_tb",
"--use_vdl",
type=bool,
default=False,
help="whether to record the data to Tensorboard.")
help="whether to record the data to VisualDL.")
parser.add_argument(
'--tb_log_dir',
'--vdl_log_dir',
type=str,
default="tb_log_dir/scalar",
help='Tensorboard logging directory for scalar.')
default="vdl_log_dir/scalar",
help='VisualDL logging directory for scalar.')
parser.add_argument(
"-p",
......
......@@ -158,12 +158,12 @@ def main():
callable(model.is_bbox_normalized):
is_bbox_normalized = model.is_bbox_normalized()
# use tb-paddle to log image
if FLAGS.use_tb:
from tb_paddle import SummaryWriter
tb_writer = SummaryWriter(FLAGS.tb_log_dir)
tb_image_step = 0
tb_image_frame = 0 # each frame can display ten pictures at most.
# use VisualDL to log image
if FLAGS.use_vdl:
from visualdl import LogWriter
vdl_writer = LogWriter(FLAGS.vdl_log_dir)
vdl_image_step = 0
vdl_image_frame = 0 # each frame can display ten pictures at most.
imid2path = dataset.get_imid2path()
for iter_id, data in enumerate(loader()):
......@@ -191,32 +191,27 @@ def main():
image_path = imid2path[int(im_id)]
image = Image.open(image_path).convert('RGB')
# use tb-paddle to log original image
if FLAGS.use_tb:
# use VisualDL to log original image
if FLAGS.use_vdl:
original_image_np = np.array(image)
tb_writer.add_image(
"original/frame_{}".format(tb_image_frame),
original_image_np,
tb_image_step,
dataformats='HWC')
vdl_writer.add_image(
"original/frame_{}".format(vdl_image_frame),
original_image_np, vdl_image_step)
image = visualize_results(image,
int(im_id), catid2name,
FLAGS.draw_threshold, bbox_results,
mask_results)
# use tb-paddle to log image with bbox
if FLAGS.use_tb:
# use VisualDL to log image with bbox
if FLAGS.use_vdl:
infer_image_np = np.array(image)
tb_writer.add_image(
"bbox/frame_{}".format(tb_image_frame),
infer_image_np,
tb_image_step,
dataformats='HWC')
tb_image_step += 1
if tb_image_step % 10 == 0:
tb_image_step = 0
tb_image_frame += 1
vdl_writer.add_image("bbox/frame_{}".format(vdl_image_frame),
infer_image_np, vdl_image_step)
vdl_image_step += 1
if vdl_image_step % 10 == 0:
vdl_image_step = 0
vdl_image_frame += 1
save_name = get_save_image_name(FLAGS.output_dir, image_path)
logger.info("Detection bbox results save in {}".format(save_name))
......@@ -246,14 +241,14 @@ if __name__ == '__main__':
default=0.5,
help="Threshold to reserve the result for visualization.")
parser.add_argument(
"--use_tb",
"--use_vdl",
type=bool,
default=False,
help="whether to record the data to Tensorboard.")
help="whether to record the data to VisualDL.")
parser.add_argument(
'--tb_log_dir',
'--vdl_log_dir',
type=str,
default="tb_log_dir/image",
help='Tensorboard logging directory for image.')
default="vdl_log_dir/image",
help='VisualDL logging directory for image.')
FLAGS = parser.parse_args()
main()
......@@ -222,12 +222,12 @@ def main():
time_stat = deque(maxlen=cfg.log_smooth_window)
best_box_ap_list = [0.0, 0] #[map, iter]
# use tb-paddle to log data
if FLAGS.use_tb:
from tb_paddle import SummaryWriter
tb_writer = SummaryWriter(FLAGS.tb_log_dir)
tb_loss_step = 0
tb_mAP_step = 0
# use VisualDL to log data
if FLAGS.use_vdl:
from visualdl import LogWriter
vdl_writer = LogWriter(FLAGS.vdl_log_dir)
vdl_loss_step = 0
vdl_mAP_step = 0
for it in range(start_iter, cfg.max_iters):
start_time = end_time
......@@ -239,12 +239,12 @@ def main():
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])}
# use tb-paddle to log loss
if FLAGS.use_tb:
# use vdl-paddle to log loss
if FLAGS.use_vdl:
if it % cfg.log_iter == 0:
for loss_name, loss_value in stats.items():
tb_writer.add_scalar(loss_name, loss_value, tb_loss_step)
tb_loss_step += 1
vdl_writer.add_scalar(loss_name, loss_value, vdl_loss_step)
vdl_loss_step += 1
train_stats.update(stats)
logs = train_stats.log()
......@@ -287,10 +287,10 @@ def main():
is_bbox_normalized, FLAGS.output_eval, map_type,
cfg['EvalReader']['dataset'])
# use tb_paddle to log mAP
if FLAGS.use_tb:
tb_writer.add_scalar("mAP", box_ap_stats[0], tb_mAP_step)
tb_mAP_step += 1
# use vdl_paddle to log mAP
if FLAGS.use_vdl:
vdl_writer.add_scalar("mAP", box_ap_stats[0], vdl_mAP_step)
vdl_mAP_step += 1
if box_ap_stats[0] > best_box_ap_list[0]:
best_box_ap_list[0] = box_ap_stats[0]
......@@ -335,15 +335,15 @@ if __name__ == '__main__':
type=str,
help="Evaluation directory, default is current directory.")
parser.add_argument(
"--use_tb",
"--use_vdl",
type=bool,
default=False,
help="whether to record the data to Tensorboard.")
help="whether to record the data to VisualDL.")
parser.add_argument(
'--tb_log_dir',
'--vdl_log_dir',
type=str,
default="tb_log_dir/scalar",
help='Tensorboard logging directory for scalar.')
default="vdl_log_dir/scalar",
help='VisualDL logging directory for scalar.')
parser.add_argument(
"--enable_ce",
type=bool,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册