mmdetection可视化

0. 可视化特征图

import matplotlib.pyplot as plt
import time
def vis(x):
    t = ((x.norm(dim=1)).squeeze()).cpu()
    plt.imshow(t, cmap=plt.get_cmap('gist_rainbow'))
    plt.show()
    # plt.imsave(f"didi/{time.strftime('%Y%m%d-%H%M%S', time.localtime())}.jpg",t, cmap=plt.get_cmap('gist_rainbow'))

1. matplotlib > hist

  • 参考:176:hxm/wetectron-master/proposal/

  • package:

.pkl文件:pickle--python对象的持久化存储
import pickle

plt.figure(dpi=200)
plt.hist([0.5], bins=50) # orange
plt.hist(p2b_2, bins=len(_p2b_2[_p2b_2 > 0]), alpha = 0.7,  label='P2BNet')
plt.hist([0.5], bins=50) # green
plt.hist(match_iou, bins=50, alpha = 0.5, label='UFO$^2$')
plt.xlim(0, 1)
plt.ylim(1, 150000)
plt.legend(fontsize=18)
plt.tick_params(labelsize=20)
plt.ticklabel_format(style='sci',scilimits=(-1,2),axis='y')
plt.xlabel("Mean IoU", fontsize=21)
plt.savefig("ufo-p2b.png",dpi=200, bbox_inches='tight')

2. MMDetection > image_demo

  • 参考:mmdetection/demo/image_demo.py
  • 基础代码:
img = '000000001639.jpg'
config_file = '../configs/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'epoch_12.pth'

model = init_detector(config_file, checkpoint_file, device='cuda:0')
result = inference_detector(model, img)
show_result_pyplot(model, img, result, score_thr=0.8)
  • 扩展1:批量图片/指定图片集合 ---> for
  • 扩展2:保存可视化图片 ---> out_file参数
# show_result_pyplot(model, img, result, score_thr=0.8)
model.show_result(
        img,
        result,
        score_thr=0.8,
        show=False, # True
        wait_time=0,
        win_name='result',
        bbox_color=(72, 101, 241),
        text_color=(72, 101, 241),
        out_file= {OUT_DIR}) # add
# api: mmdet.models.detectors.base.BaseDetector.show_result()
  • 扩展3:可视化gt ---> in: 标注文件
  • 扩展4:可视化点

你可能感兴趣的:(mmdetection可视化)