import sys import os import random 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_test63/AD_dsxw_test63.py' checkpoint_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test63/epoch_46.pth' config_file_2 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test62/AD_dsxw_test62.py' checkpoint_file_2 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test62/epoch_44.pth' img_path = '/home/shanwei-luo/userdata/datasets/dsxw_test_SMD11_2022_0301_0315/images/' label_path = '/home/shanwei-luo/userdata/datasets/dsxw_test_SMD11_2022_0301_0315/labels/' model_1 = init_detector(config_file_1, checkpoint_file_1, device='cuda:0') model_2 = init_detector(config_file_2, checkpoint_file_2, device='cuda:1') 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 = [] results_2 = [] step = 32 while index0: res_predict = 1 imgs_results_1.append(res_predict) imgs_results_2 = [] for result in results_2: res_predict = 0 for i in result: if i.shape[0]>0: res_predict = 1 imgs_results_2.append(res_predict) print(len(imgs_results_1), len(imgs_results_2)) imgs_results = [] for r1, r2 in zip(imgs_results_1, imgs_results_2): if r1 == 1 or r2 == 1: imgs_results.append(1) else: imgs_results.append(0) print(len(imgs_results)) count_ng = 0 count_ok = 0 for i in range(len(imgs_labels)): if imgs_labels[i]==0 and imgs_labels[i]==imgs_results_1[i]: count_ok += 1 if imgs_labels[i]==1 and imgs_labels[i]==imgs_results_1[i]: count_ng += 1 print(count_ok/label_ok, count_ng/label_ng) count_ng = 0 count_ok = 0 for i in range(len(imgs_labels)): if imgs_labels[i]==0 and imgs_labels[i]==imgs_results_2[i]: count_ok += 1 if imgs_labels[i]==1 and imgs_labels[i]==imgs_results_2[i]: count_ng += 1 print(count_ok/label_ok, count_ng/label_ng) count_ng = 0 count_ok = 0 for i in range(len(imgs_labels)): if imgs_labels[i]==0 and imgs_labels[i]==imgs_results[i]: count_ok += 1 if imgs_labels[i]==1 and imgs_labels[i]==imgs_results[i]: count_ng += 1 #print(count_ok, count_ng) #print(count_ng/label_ng) print(count_ok/label_ok, count_ng/label_ng)