open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.54k stars 9.46k forks source link

Test #655

Closed HuangQinJian closed 3 years ago

HuangQinJian commented 5 years ago

When I predict the image,I set the configscore_thr=0.3, nms=dict(type='soft_nms', iou_thr=0.7),:

test_cfg = dict(
    rpn=dict(
        nms_across_levels=False,
        nms_pre=1000,
        nms_post=1000,
        max_num=1000,
        nms_thr=0.7,
        min_bbox_size=0),
    rcnn=dict(
        score_thr=0.3, nms=dict(type='soft_nms', iou_thr=0.7), max_per_img=100),
    keep_all_stages=False)

predict:

#!/usr/bin/env python
# coding=UTF-8
'''
@Description:
@Author: HuangQinJian
@LastEditors: HuangQinJian
@Date: 2019-05-08 09:50:15
@LastEditTime: 2019-05-16 15:52:13
'''
import os

import pandas as pd
import numpy as np

import mmcv
from mmcv.runner import load_checkpoint
from mmdet.apis import inference_detector, show_result
from mmdet.models import build_detector
from tqdm import tqdm

cfg = mmcv.Config.fromfile(
    'configs/cascade_rcnn_r50_fpn_1x.py')
cfg.model.pretrained = 'work_dirs/epoch_20.pth'

# construct the model and load checkpoint
model = build_detector(cfg.model, test_cfg=cfg.test_cfg)
_ = load_checkpoint(
    model, cfg.model.pretrained)

imgs_dir = '/data1/hqj/TBE/wangjinhua_val'
img_names = os.listdir(imgs_dir)

submit = pd.DataFrame()

filenameList = []

X1List = []
X2List = []
X3List = []
X4List = []

Y1List = []
Y2List = []
Y3List = []
Y4List = []

ScoreList = []
TypeList = []

# for img_name in img_names:
for i, img_name in enumerate(tqdm(img_names)):
    path = os.path.join(imgs_dir, img_name)
    # test a single image
    img = mmcv.imread(path)
    result = inference_detector(model, img, cfg)
    if len(result) != 0:
        for cat, bbox in enumerate(result):
            # print(j, box)
            num = len(bbox)
            if num != 0:
                for k in range(num):
                    filenameList.append(img_name)
                    X1List.append(bbox[k][0])
                    Y1List.append(bbox[k][1])
                    X2List.append(bbox[k][2])
                    Y2List.append(bbox[k][1])
                    X3List.append(bbox[k][2])
                    Y3List.append(bbox[k][3])
                    X4List.append(bbox[k][0])
                    Y4List.append(bbox[k][3])
                    ScoreList.append(bbox[k][4])
                    TypeList.append(cat)
    else:
        filenameList.append(img_name)
        X1List.append(0)
        Y1List.append(0)
        X2List.append(0)
        Y2List.append(0)
        X3List.append(0)
        Y3List.append(0)
        X4List.append(0)
        Y4List.append(0)
        ScoreList.append(0)
        TypeList.append(0)

submit['filename'] = filenameList
submit['X1'] = X1List
submit['Y1'] = Y1List
submit['X2'] = X2List
submit['Y2'] = Y2List
submit['X3'] = X3List
submit['Y3'] = Y3List
submit['X4'] = X4List
submit['Y4'] = Y4List
submit['score'] = ScoreList
submit['type'] = TypeList

submit.to_csv('result_wangjinhua_cascadercnn.csv', index=None)

the output box score still have lower than 0.3 and the overlap is so big,why?

image

image

hellock commented 5 years ago

Because you use Soft-NMS instead of NMS.

HuangQinJian commented 5 years ago

Because you use Soft-NMS instead of NMS.

I also try nms ,it still did not work. the output box score still have lower than 0.3 and the overlap is so big

ideaRunner commented 5 years ago

Any progress? @HuangQinJian I also found there are some post processing at show_result function. So that there will be a little difference about the results you get from inference_detector and show_result

wkoa commented 5 years ago

Have you solved this problem? I have met the same problem. Any ideas for NMS?