import os from utils.eval_utils import evaluate_on_cpu, evaluate_on_gpu, get_preds_gpu, voc_eval, parse_gt_rec from read_xml import readXMLAndReturnBox,readCheckResultTxt print('---') #readXMLAndReturnBox('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/VOC2007/Annotations/2019_07_14-10_11_34_left.xml') box_1 = readXMLAndReturnBox('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/VOC2007/Annotations/2019_07_14-09_07_14_left.xml') #def voc_eval(gt_dict, val_preds, classidx, iou_thres=0.5, use_07_metric=False) #gt_dict['2019_07_14-08_06_34_left.txt'] = box_1 #gt_dict.setdefault('2019_07_14-08_06_34_left.txt',[]).append(box_1) #val_preds = [['2019_07_14-09_07_14_left',1199, 412, 1240, 488, 0,0.96,0]] xml_lists = os.listdir('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/VOC2007/Annotations/') txt_lists = os.listdir('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/detect_result2/') xml_list = [] ''' for file_index in xml_lists: print(file_index) ''' xml_list = [os.path.join('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/VOC2007/Annotations/',file_index) for file_index in xml_lists] txt_list = [os.path.join('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/detect_result2/',file_index) for file_index in txt_lists] ap_total =[] for file_index in range(len(xml_list)): gt_dict = {} box_1 = readXMLAndReturnBox(xml_list[file_index]) gt_dict[xml_lists[file_index]] = box_1 val_index = readCheckResultTxt(txt_list[file_index],xml_lists[file_index]) print(gt_dict) print(val_index) npos, nd, rec, prec, ap = voc_eval(gt_dict, val_index, 0, iou_thres=0.5) ap_total.append(ap) t_mAP = 0.00 for index_ap in ap_total: t_mAP = t_mAP + index_ap mAP = t_mAP/len(ap_total) print("="*30) print("mAP:") print(mAP) ''' val_index = readCheckResultTxt('/home/star/RCNN-20200503/YOLOv3_TensorFlow/data/detect_result2/2019_07_14-08_06_34_left.txt','2019_07_14-08_06_34_left.txt') #val_index.insert(0,'2019_07_14-08_08_34_left.txt') print(val_index) print(gt_dict) #val_preds = [[['2019_07_14-09_07_14_left',929, 428, 973, 479, 0.96,0], ['2019_07_14-09_07_14_left',1199, 412, 1240, 488, 0.96,0], ['2019_07_14-09_07_14_left',1206, 414, 1279, 564, 0.96,0]]] #./darknet detector map cfg/voc.data cfg/yolov3-voc.cfg backup/yolov3-voc_80172.weights #gt_dict = {'2019_07_14-08_06_34_left.txt': [[929, 428, 973, 479, 0], [1199, 412, 1240, 488, 0], [1206, 414, 1279, 564, 0]]} npos, nd, rec, prec, ap = voc_eval(gt_dict, val_index, 0, iou_thres=0.5) print(ap) '''