Detectron 目标检测结果可视化

1. 绘制 detectron 目标检测的 loss-accuracy 曲线

首先使用 tee 命令将训练日志重定向到日志文件 train_info.log

  1. $ python tools/train_net.py --cfg experiment/fast_rcnn_resnet50_FPN.yaml OUTPUT_DIR experiment/detectron_result | tee experiment/train_info.log

训练日志的主要内容为

  1. json_stats: {
  2. "accuracy_cls": 0.000000,
  3. "eta": "29 days, 16:00:50",
  4. "iter": 0,
  5. "loss": 6.594362,
  6. ...
  7. "lr": 0.003333,
  8. "mb_qsize": 64,
  9. "mem": 9376,
  10. "time": 14.240279
  11. }

根据训练日志绘制 loss-accuracy 曲线的 python 脚本如下:

  1. import json
  2. import re
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. log_file = 'experiment/train_info.log'
  6. with open(log_file) as f:
  7. # 提取信息
  8. pattern = re.compile('json_stats: {.*}')
  9. info_list = pattern.findall(f.read())
  10. parsed = None
  11. try:
  12. parsed = [json.loads('{' + string.split('{')[1]) for string in info_list]
  13. except:
  14. print('Json format is not correct !!!')
  15. exit(1)
  16. if parsed:
  17. iter = np.array([int(string['iter']) for string in parsed])
  18. loss = np.array([int(string['loss']) for string in parsed])
  19. accuracy = np.array([float(string['accuracy_cls']) for string in parsed])
  20. # 绘制图形
  21. plt.figure('Figure of Loss-Accuracy', figsize=(8,6), frameon=True)
  22. plt.plot(iter, accuracy, color='red', linestyle='--', linewidth=1, label="accuracy")
  23. plt.plot(iter, loss, 'b-', lw=1, label='loss')
  24. plt.xlim((iter[0], len(iter)))
  25. plt.ylim((0, max(loss)))
  26. plt.title('The Information of Loss and Accuracy', color='green')
  27. plt.legend(loc='upper right')
  28. plt.show()
  29. else:
  30. print('There is no loss information in file "{:s}".format(log_name)')

loss-accuracy 曲线的图形示例如下

Loss-Accuracy 曲线图

2. 检测结果可视化

  1. $ python tools/visualize_results.py \
  2. --dataset experiment_val \
  3. --detections experiment/detections.pkl \
  4. --output-dir experiment/result_jpg
-------------本文结束 感谢阅读-------------
0%