|
- import sys
- import os
- import random
- import numpy as np
- sys.path.append("/home/shanwei-luo/userdata/mmdetection")
- from mmdet.apis import (async_inference_detector, inference_detector,
- init_detector, show_result_pyplot)
-
- config_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test72_ft/AD_dsxw_test72_ft.py'
- checkpoint_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test72_ft/epoch_10.pth'
-
- img_path = '/home/shanwei-luo/userdata/datasets/dsxw_dataset_v12/dsxw_test/images/'
- label_path = '/home/shanwei-luo/userdata/datasets/dsxw_dataset_v12/dsxw_test/labels/'
-
- model_1 = init_detector(config_file_1, checkpoint_file_1, device='cuda:0')
-
- imgs = os.listdir(img_path)
- labels = os.listdir(label_path)
- #img_id = random.randint(0, len(label_path))
- label_ng = len(labels)
- label_ok = len(imgs)-label_ng
- print(label_ok, label_ng)
- imgs_labels = []
- imgs_name = []
- for img in imgs:
- label = img[:-3]+'txt'
- res_label = 0
- if label in labels:
- res_label = 1
- imgs_labels.append(res_label)
- imgs_name.append(img_path+img)
- print(len(imgs_labels))
- print("before infer")
- index = 0
- num = len(imgs_name)
- results_1 = []
- step = 256
- while index<num:
- index += step
- if index < num:
- results_1_tmp = inference_detector(model_1, imgs_name[index-step:index])
- else:
- results_1_tmp = inference_detector(model_1, imgs_name[index-step:num])
- results_1 += results_1_tmp
- print(len(results_1))
- print("after infer")
-
- #score_thrs = [0.01, 0.011, 0.012, 0.013, 0.014, 0.015, 0.016, 0.017, 0.018, 0.019, 0.02]
- for score_thr in np.arange(0.01, 0.05, 0.001):
- imgs_results_1 = []
- for result in results_1:
- res_predict = 0
- for i in result:
- for j in range(i.shape[0]):
- if i[j, 4]>score_thr:
- res_predict = 1
- imgs_results_1.append(res_predict)
-
- count_ng = 0
- count_ok = 0
- for i in range(len(imgs_labels)):
- if imgs_labels[i]==0 and imgs_results_1[i]==0:
- count_ok += 1
- if imgs_labels[i]==1 and imgs_results_1[i]==1:
- count_ng += 1
- print("score_thr:", score_thr, " recall(ok):", count_ok/label_ok, " recall(ng):", count_ng/label_ng)
|