object has no attribute ‘show_result‘,mmdetection3.0最新检测方法

之前是使用 show_result 来绘制检测结果,并保存,现在已经无法使用,会报错
‘xxx Model’ object has no attribute ‘show_result’

最新的方法如下:

# -*- coding: UTF-8 -*-

import os
from mmdet.apis import init_detector, inference_detector
from mmdet.registry import VISUALIZERS
import mmcv

# 使用前修改下面的路径
image_path = r'E:\Models\mmdetection-3.0.0\data\coco\test\JPEGImages'
savepath = r'E:\Models_exp\mmdetection\yolact\save_for_clamp'

config_file = r'E:\Models\mmdetection-3.0.0\work_dirs\yolact_r50_1xb8-55e_coco_clamp\yolact_r50_1xb8-55e_coco_clamp.py'
checkpoint_file = r'E:\Models\mmdetection-3.0.0\work_dirs\yolact_r50_1xb8-55e_coco_clamp\epoch_55.pth'

# gpu 不行 会 Out of memory
device = 'cuda:0'

model = init_detector(config_file, checkpoint_file, device=device)

visualizer = VISUALIZERS.build(model.cfg.visualizer)
# the dataset_meta is loaded from the checkpoint and
# then pass to the model in init_detector
visualizer.dataset_meta = model.dataset_meta

for filename in os.listdir(image_path):
    imgpath = os.path.join(image_path, filename)

    print('process ', imgpath)
    img = mmcv.imread(imgpath)
    result = inference_detector(model, img)
    out_file = os.path.join(savepath, filename)

    ### old implementation invalid
    # show_result_pyplot(model, img, result, out_file, score_thr=0.3)
    ###

    # show the results
    visualizer.add_datasample('result',
                              img, data_sample=result,
                              draw_gt=False,
                              wait_time=0,
                              out_file=out_file,
                              pred_score_thr=0.3
                              )
    # vis
    # visualizer.show()
    # break

有问题,后期维护更新,欢迎留言、进群讨论或私聊:【群号:392784757】

你可能感兴趣的:(deep,learning,python)