import sys import os import random import numpy as np import json sys.path.append("/home/shanwei-luo/userdata/mmdetection") from mmdet.apis import (async_inference_detector, inference_detector, init_detector, show_result_pyplot) data_coco = json.load(open('/home/shanwei-luo/userdata/pd_datasets/20220606_coco/annotations/val_cat_mode.json')) data_name = data_coco["images"] data_ann = data_coco['annotations'] boxes = {} for res in data_ann: print(res) img_id_1 = res["image_id"] img_name = data_name[int(img_id_1)]["file_name"] #print(img_name) #print(res) bbox = res["bbox"] label = res["category_id"] bbox.append(int(label)) if img_name in boxes.keys(): boxes[img_name].append(bbox) else: boxes[img_name]=[] boxes[img_name].append(bbox) #print(boxes) config_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_pd_test01/AD_pd_test01.py' checkpoint_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_pd_test01/epoch_18.pth' img_path = '/home/shanwei-luo/userdata/pd_datasets/20220606_coco/images/' model_1 = init_detector(config_file_1, checkpoint_file_1, device='cuda:0') imgs = os.listdir(img_path) #img_id = random.randint(0, len(label_path)) imgs_labels = [] imgs_name = [] num_ng = 0 for i in range(len(data_name)): res_label = 0 if data_name[i]["file_name"] in boxes.keys(): res_label = 1 num_ng += 1 imgs_labels.append(res_label) imgs_name.append(img_path+data_name[i]["file_name"]) num_ok = len(data_name)-num_ng print(len(imgs_labels), num_ok, num_ng) imgs_name = imgs_name[:10] print("before infer") index = 0 num = len(imgs_name) results_1 = [] step = 64 while indexscore_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 '''if imgs_labels[i]==1 and imgs_results_1[i]==0: print(imgs_name[i])''' print("score_thr:", score_thr, " recall(ok):", count_ok/num_ok, " recall(ng):", count_ng/num_ng)