def annotate(): pingit = Detector() data ={} data['results'] = [] rgb_folder = "/Data2TB/correctly_registered/S12/test/color/" d_folder = "/Data2TB/correctly_registered/S12/test/depth_normalized/" rgb_images = [f for f in listdir(rgb_folder) if isfile(join(rgb_folder, f))] jsonprop = "/Data2TB/correctly_registered/S12/test/output.json" jsongt = "/Data2TB/sample/annotations.json" for image in rgb_images: rgb_img = cv2.imread(rgb_folder + image) d_img = cv2.imread(d_folder + image.replace(".jpg",".png"),cv2.IMREAD_GRAYSCALE) proposals, gtobjects = common_functions.get_proposal_and_gt_boxes(image,jsonprop,jsongt) for prop in proposals: imgtemp_rgb = rgb_img.copy() imgtemp_rgb = imgtemp_rgb[...,::-1] imgtemp_d = d_img.copy() imgtemp_d = imgtemp_d.reshape(imgtemp_d.shape[0],imgtemp_d.shape[1],1) combined_image = np.concatenate((imgtemp_rgb, imgtemp_d), axis=2) #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0] ymin = prop[1] xmax = prop[2] ymax = prop[3] xmin,ymin,xmax,ymax = common_functions.refine_bounding_box(xmin,ymin,xmax,ymax) roi_combined_image = combined_image[ymin:ymax, xmin:xmax] #roi_rgb = imgtemp_rgb[ymin:ymax, xmin:xmax] width_original = roi_combined_image.shape[1] width_diff = width_original - 48 roi_detect = cv2.resize(roi_combined_image, (48,48)) roi_detect = roi_detect.reshape(1,48,48,4) roi_detect = (roi_detect.astype('float32') - 127.5)/128 cls_scores, reg,landmark = pingit.predict(roi_detect) bb = reg[0] lm = landmark[0] bb,lm = common_functions.rescale_detections_to_full_image(bb,lm,width_original, prop) ind = np.argmax(cls_scores[0]) if(ind == 1): cv2.rectangle(rgb_img,(bb[0], bb[1]), (bb[2], bb[3]),(0,0,255), 1) cv2.imshow("image",rgb_img) cv2.waitKey()
def evaluate_3c(index): config = singleton.configuration._instance.config data = {} data['results'] = [] tf.logging.set_verbosity(tf.logging.FATAL) logging.getLogger("tensorflow").setLevel(logging.ERROR) pingit = common_functions.Detector(index, config) images_folder = config.rgb_folder display_folder = config.display_folder images = [ f for f in listdir(images_folder) if isfile(join(images_folder, f)) ] jsonprop = config.jsonprop jsongt = config.jsongt iou_props_total = 0 iou_detections_total = 0 total_detections = 0 total_gt = 0 total_tp = 0 total_fp = 0 total_pckh_precision = 0 master_count = 0 for image in images: positive_props = [] detections_regressed = [] img = cv2.imread(images_folder + image) proposals, gtobjects = common_functions.get_proposal_and_gt_boxes( image, jsonprop, jsongt) display_image = cv2.imread(display_folder + image) count = 0 propcount = 0 for prop in proposals: total_detections += len(proposals) imgtemp = img.copy() #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0] ymin = prop[1] xmax = prop[2] ymax = prop[3] xmin, ymin, xmax, ymax = common_functions.refine_bounding_box( xmin, ymin, xmax, ymax) roi = imgtemp[ymin:ymax, xmin:xmax] width_original = roi.shape[1] width_diff = width_original - 48 roi_detect = cv2.resize(roi, (48, 48)) roi_detect = roi_detect.reshape(1, 48, 48, 3) roi_detect = (roi_detect.astype('float32') - 127.5) / 128 roi_detect = roi_detect[..., ::-1] cls_scores, reg, landmark = pingit.predict(roi_detect) bb = reg[0] lm = landmark[0] ind = np.argmax(cls_scores[0]) if (ind == 1): positive_props.append(prop) bb, lm = common_functions.rescale_detections_to_full_image( bb, lm, width_original, prop) detection = [bb, lm] detections_regressed.append(detection) ious = eval_functions.get_iou_totals_per_image(gtobjects, positive_props, detections_regressed, images_folder + image) #shoulder_precisions = eval_functions.get_shoulder_precisions(gtobjects, detections_regressed) iou_props_total += ious[0] iou_detections_total += ious[1] total_gt += ious[2] total_tp += ious[3] total_fp += ious[4] total_pckh_precision += ious[5] #total_precisions += ious[5] if (ious[0] != 0 and ious[1] != 0): master_count += 1 av_iou_prop = iou_props_total / master_count av_iou_detection = iou_detections_total / master_count recall = total_tp / total_gt miss_rate = total_fp / (total_tp + total_fp) av_pckh_precision = total_pckh_precision / (master_count) data['results'].append({ 'at': str(index), 'recall': recall, 'miss_rate': miss_rate, 'av_iou': av_iou_detection, 'pckh': av_pckh_precision }) with open( config.results_out + config.mtcnn_model + config.bbox_loss + ".json", 'a') as outfile: json.dump(data, outfile, indent=4) return av_iou_detection, recall, miss_rate
def evaluate_4c(pingit, threshold, percentage): tf.logging.set_verbosity(tf.logging.FATAL) logging.getLogger("tensorflow").setLevel(logging.ERROR) rgb_folder = "/Data2TB/correctly_registered/S12/test/color/" d_folder = "/Data2TB/correctly_registered/S12/test/depth_normalized/" display_folder = "/Data2TB/correctly_registered/S12/test/color/" jsonprop = "/Data2TB/correctly_registered/S12/test/output.json" jsongt = "/Data2TB/sample/annotations.json" rgb_images = [ f for f in listdir(rgb_folder) if isfile(join(rgb_folder, f)) ] iou_props_total = 0 iou_detections_total = 0 total_gt = 0 total_tn = 0 total_tp = 0 total_fp = 0 total_outl = 0 total_fn = 0 total_pckh_precision = 0 master_count = 0 #for i in range(0,3):#image in rgb_images: for image in rgb_images: total_detections = 0 #image = rgb_images[i] positive_props = [] detections_regressed = [] rgb_img = cv2.imread(rgb_folder + image) d_img = cv2.imread(d_folder + image.replace(".jpg", ".png"), cv2.IMREAD_GRAYSCALE) proposals, gtobjects = common_functions.get_proposal_and_gt_boxes( image, jsonprop, jsongt) display_image = cv2.imread(display_folder + image) count = 0 propcount = 0 for prop in proposals: total_detections += 1 imgtemp_rgb = rgb_img.copy() imgtemp_rgb = imgtemp_rgb[..., ::-1] imgtemp_d = d_img.copy() imgtemp_d = imgtemp_d.reshape(imgtemp_d.shape[0], imgtemp_d.shape[1], 1) combined_image = np.concatenate((imgtemp_rgb, imgtemp_d), axis=2) #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0] ymin = prop[1] xmax = prop[2] ymax = prop[3] xmin, ymin, xmax, ymax = common_functions.refine_bounding_box( xmin, ymin, xmax, ymax) roi_combined_image = combined_image[ymin:ymax, xmin:xmax] #roi_rgb = imgtemp_rgb[ymin:ymax, xmin:xmax] width_original = roi_combined_image.shape[1] width_diff = width_original - 48 roi_detect = cv2.resize(roi_combined_image, (48, 48)) roi_detect = roi_detect.reshape(1, 48, 48, 4) roi_detect = (roi_detect.astype('float32') - 127.5) / 128 #roi_detect_rgb = cv2.resize(roi_rgb, (48,48)) #roi_detect_rgb = roi_detect_rgb.reshape(48,48,3) #roi_detect_rgb = (roi_detect_rgb.astype('float32') - 127.5)/128 #roi_detect_rgb = roi_detect_rgb[...,::-1] # #roi_d = imgtemp_d[ymin:ymax, xmin:xmax] # #width_original = roi_d.shape[1] #width_diff = width_original - 48 # ##r,g,b = roi_d.split() #roi_detect_d = cv2.resize(roi_d, (48,48)) #roi_detect_d = roi_detect_d.reshape(48,48,1) #roi_detect_d = (roi_detect_d.astype('float32') - 127.5)/128 ##roi_detect = roi_detect[...,::-1] # ##roi_detect = np.dstack((roi_detect_rgb,roi_detect_d)) #roi_detect = np.concatenate((roi_detect_rgb, roi_detect_d), axis=2) #roi_detect = roi_detect.reshape(1,48,48,4) #roi_detect = (roi_detect.astype('float32') - 127.5)/128 cls_scores, reg, landmark = pingit.predict(roi_detect) bb = reg[0] lm = landmark[0] #ind = np.argmax(cls_scores[0]) #if(ind == 1): if (cls_scores[0][1] >= threshold): positive_props.append(prop) bb, lm = common_functions.rescale_detections_to_full_image( bb, lm, prop) detection = [bb, lm] detections_regressed.append(detection) ious = get_iou_totals_per_image(gtobjects, positive_props, detections_regressed, rgb_folder + image, percentage) #shoulder_precisions = eval_functions.get_shoulder_precisions(gtobjects, detections_regressed) iou_props_total += ious[0] iou_detections_total += ious[1] total_gt += ious[2] total_tp += ious[3] total_fp += ious[4] total_outl += ious[6] total_fn += ious[7] total_tn += total_detections - ious[3] - ious[4] - ious[6] total_pckh_precision += ious[5] #total_precisions += ious[5] if (ious[0] != 0 and ious[1] != 0): master_count += 1 av_iou_prop = iou_props_total / master_count av_iou_detection = iou_detections_total / master_count recall = total_tp / total_gt miss_rate = total_fp / (total_fp + total_tn) precision = total_tp / total_detections av_pckh_precision = total_pckh_precision / (master_count) return av_iou_detection, recall, miss_rate, av_pckh_precision, av_iou_prop
def evaluate_3c(pingit, threshold, percentage, images_folder): data = {} tf.logging.set_verbosity(tf.logging.FATAL) logging.getLogger("tensorflow").setLevel(logging.ERROR) #images_folder = "/Data2TB/correctly_registered/S12/test/color/" display_folder = "/Data2TB/correctly_registered/S12/test/color/" images = [ f for f in listdir(images_folder) if isfile(join(images_folder, f)) ] jsonprop = "/Data2TB/correctly_registered/S12/test/output.json" jsongt = "/Data2TB/sample/annotations.json" iou_props_total = 0 iou_detections_total = 0 total_gt = 0 total_tn = 0 total_tp = 0 total_fp = 0 total_outl = 0 total_fn = 0 total_pckh_precision = 0 master_count = 0 #for i in range(0,3): for image in images: total_detections = 0 #image = images[i] positive_props = [] detections_regressed = [] img = cv2.imread(images_folder + image) proposals, gtobjects = common_functions.get_proposal_and_gt_boxes( image, jsonprop, jsongt) display_image = cv2.imread(display_folder + image) count = 0 propcount = 0 for prop in proposals: total_detections += 1 imgtemp = img.copy() #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0] ymin = prop[1] xmax = prop[2] ymax = prop[3] xmin, ymin, xmax, ymax = common_functions.refine_bounding_box( xmin, ymin, xmax, ymax) roi = imgtemp[ymin:ymax, xmin:xmax] width_original = roi.shape[1] width_diff = width_original - 48 roi_detect = cv2.resize(roi, (48, 48)) roi_detect = roi_detect.reshape(1, 48, 48, 3) roi_detect = (roi_detect.astype('float32') - 127.5) / 128 roi_detect = roi_detect[..., ::-1] cls_scores, reg, landmark = pingit.predict(roi_detect) bb = reg[0] lm = landmark[0] if (cls_scores[0][1] >= threshold): positive_props.append(prop) bb, lm = common_functions.rescale_detections_to_full_image( bb, lm, prop) detection = [bb, lm] detections_regressed.append(detection) ious = get_iou_totals_per_image(gtobjects, positive_props, detections_regressed, images_folder + image, percentage) #shoulder_precisions = eval_functions.get_shoulder_precisions(gtobjects, detections_regressed) iou_props_total += ious[0] iou_detections_total += ious[1] total_gt += ious[2] total_tp += ious[3] total_fp += ious[4] total_outl += ious[6] total_fn += ious[7] total_tn += total_detections - ious[3] - ious[4] - ious[6] total_pckh_precision += ious[5] #total_precisions += ious[5] if (ious[0] != 0 and ious[1] != 0): master_count += 1 av_iou_prop = iou_props_total / master_count av_iou_detection = iou_detections_total / master_count recall = total_tp / total_gt miss_rate = total_fp / (total_fp + total_tn) precision = total_tp / (total_tp + total_fp) av_pckh_precision = total_pckh_precision / (master_count) return av_iou_detection, recall, miss_rate, av_pckh_precision, av_iou_prop
def evaluate_4c(pingit,ayre,images_folder): rgb_folder = "/Data2TB/correctly_registered/S12/test/color/" images_folder = rgb_folder d_folder = "/Data2TB/correctly_registered/S12/test/depth_normalized/" display_folder = "/Data2TB/correctly_registered/S12/test/color/" jsonprop = "/Data2TB/correctly_registered/S12/test/output.json" jsongt = "/Data2TB/sample/annotations.json" rgb_images = [f for f in listdir(rgb_folder) if isfile(join(rgb_folder, f))] jsonprop = "/Data2TB/correctly_registered/S12/test/output.json" jsongt = "/Data2TB/sample/annotations.json" #list_thresholds = [0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.6,0.7,0.8,0.9] list_thresholds = [0.9] list_percentages = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9] percentage = 0.5 list_precisions = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] list_recalls = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] list_gt = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_gt = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_tn = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_tp = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_fp = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_outl = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_fn = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_pckh_precision = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] total_true_detections_p5 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] iou_props_total = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] iou_detections_total = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] master_count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] av_iou_prop = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] av_iou_detection = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] recall = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] miss_rate = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] precision = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] av_pckh_precision = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] for image in rgb_images: total_proposals = 0 #image = images[i] positive_props = [] detections_regressed = [] rgb_img = cv2.imread(rgb_folder + image) d_img = cv2.imread(d_folder + image.replace(".jpg",".png"),cv2.IMREAD_GRAYSCALE) proposals, gtobjects = common_functions.get_proposal_and_gt_boxes(image,jsonprop,jsongt) count = 0 propcount = 0 list_positive_props = [[],[],[],[],[],[],[],[],[],[],[],[],[],[]] list_detections_regressed = [[],[],[],[],[],[],[],[],[],[],[],[],[],[]] for prop in proposals: total_proposals += 1 imgtemp_rgb = rgb_img.copy() imgtemp_rgb = imgtemp_rgb[...,::-1] imgtemp_d = d_img.copy() imgtemp_d = imgtemp_d.reshape(imgtemp_d.shape[0],imgtemp_d.shape[1],1) combined_image = np.concatenate((imgtemp_rgb, imgtemp_d), axis=2) #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0] ymin = prop[1] xmax = prop[2] ymax = prop[3] xmin,ymin,xmax,ymax = common_functions.refine_bounding_box(xmin,ymin,xmax,ymax) roi_combined_image = combined_image[ymin:ymax, xmin:xmax] #roi_rgb = imgtemp_rgb[ymin:ymax, xmin:xmax] width_original = roi_combined_image.shape[1] width_diff = width_original - 48 roi_detect = cv2.resize(roi_combined_image, (48,48)) roi_detect = roi_detect.reshape(1,48,48,4) roi_detect = (roi_detect.astype('float32') - 127.5)/128 #roi_detect_rgb = cv2.resize(roi_rgb, (48,48)) #roi_detect_rgb = roi_detect_rgb.reshape(48,48,3) #roi_detect_rgb = (roi_detect_rgb.astype('float32') - 127.5)/128 #roi_detect_rgb = roi_detect_rgb[...,::-1] cls_scores, reg,landmark = pingit.predict(roi_detect) bb = reg[0] lm = landmark[0] for i in range(len(list_percentages)): if(cls_scores[0][1] >= 0.9): list_positive_props[i].append(prop) bbtmp,lmtmp = common_functions.rescale_detections_to_full_image(bb,lm, prop) list_detections_regressed[i].append([bbtmp,lmtmp]) for i in range(len(list_percentages)): results = get_iou_totals_per_image(gtobjects, list_positive_props[i], list_detections_regressed[i],images_folder + image,list_percentages[i]) iou_props_total[i] += results[0] iou_detections_total[i] += results[1] total_gt[i] += results[2] total_tp[i] += results[3] total_fp[i] += results[4] total_outl[i] += results[6] total_fn[i] += results[7] total_tn[i] += total_proposals - results[3] - results[4] - results[6] total_pckh_precision[i] += results[5] total_true_detections_p5[i] += results[8] #total_precisions += ious[5] if(results[0] != 0 and results[1] != 0): master_count[i] += 1 for i in range(len(list_percentages)): av_iou_prop[i] = iou_props_total[i]/master_count[i] av_iou_detection[i] = iou_detections_total[i]/master_count[i] recall[i] = total_tp[i] / total_gt[i] miss_rate[i] = total_fp[i] / (total_fp[i] + total_tn[i]) precision[i] = total_tp[i] / (total_tp[i] + total_fp[i]) av_pckh_precision[i] = total_pckh_precision[i]/(master_count[i]) #recall[i] = total_true_detections_p5[i] / total_gt[i] #precision[i] = total_true_detections_p5[i] / (total_true_detections_p5[i] + total_fp[i]) #print("Threshold: " , round(list_thresholds[i],2)) #print("Average prop IOU: " , round(av_iou_prop[i],2)) #print("Average detection IOU: " , round(av_iou_detection[i],2)) #print("PCKH: " , round(av_pckh_precision[i],2)) #print("Recall: " , round(recall[i],2)) #print("Precision: " , round(precision[i],2)) print("Average PCKH: " , round(av_pckh_precision[i],2)) #print("") #print("") #print("Average prop IOU: " , round(av_iou_prop[13],2)) #print("Average detection IOU: " , round(av_iou_detection[13],2)) #print("Average PCKH: " , round(av_pckh_precision[6],2)) return av_iou_detection,recall, miss_rate,av_pckh_precision,av_iou_prop
def evaluate_3c(index): config = singleton.configuration._instance.config data = {} data['results'] = [] tf.logging.set_verbosity(tf.logging.FATAL) logging.getLogger("tensorflow").setLevel(logging.ERROR) pingit = common_functions.Detector(index, config) images_folder = config.rgb_folder display_folder = config.display_folder images = [ f for f in listdir(images_folder) if isfile(join(images_folder, f)) ] jsonprop = config.jsonprop jsongt = config.jsongt iou_props_total = 0 iou_detections_total = 0 total_detections = 0 total_gt = 0 total_tp = 0 total_fp = 0 total_pckh_precision = 0 master_count = 0 #val_folder = "/Data2TB/chl_data/mod/val/pos_neg_png_48/" images = [ f for f in listdir(images_folder) if isfile(join(images_folder, f)) ] pos = 0 neg = 0 for image in images: img = cv2.imread(images_folder + image, -1) #img = cv2.imread(val_folder + "video_fifth_2018-04-23_CAM1_1524502510848_id_791_index_0.png") positive_props = [] detections_regressed = [] img = cv2.imread(images_folder + image, -1) #img = cv2.imread("/Data2TB/chl_data/mod/val/pos_png_48/video_fifth_2018-04-23_CAM1_1524502858816_id_831_index_0.png",-1) ##roi_detect = img.reshape(1, 48,48,3) ##roi_detect = (roi_detect.astype('float32') - 127.5)/128 ##roi_detect = roi_detect[...,::-1] proposals, gtobjects = common_functions.get_proposal_and_gt_boxes_mod( image, jsonprop, jsongt) display_image = cv2.imread(display_folder + image) # # count = 0 propcount = 0 for prop in proposals: total_detections += len(proposals) imgtemp = img.copy() #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0][0] ymin = prop[0][1] xmax = prop[0][2] ymax = prop[0][3] headpoint = prop[1] xmin, ymin, xmax, ymax = common_functions.refine_bounding_box( xmin, ymin, xmax, ymax) roi = imgtemp[ymin:ymax, xmin:xmax] x_roi = headpoint[0] - xmin y_roi = headpoint[1] - ymin headpoint_roi = [y_roi, x_roi] roi = mod.get_channels(roi, headpoint_roi) # #roi1copy = roi1.copy() encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 95] result, encimg = cv2.imencode('.jpg', roi, encode_param) roi = cv2.imdecode(encimg, 1) #cv2.imshow("WAS IT LOS", roi) #cv2.waitKey() count += 1 # #continue # #videos_holland_orbbec_2018-02-21_CAM2_1519232343120_id_66320_index_0.png width_original = roi.shape[1] width_diff = width_original - 48 # roi_detect = cv2.resize(roi, (48, 48)) roi_detect = roi_detect.reshape(1, 48, 48, 3) roi_detect = (roi_detect.astype('float32') - 127.5) / 128 roi_detect = roi_detect[..., ::-1] #cls_scores = common_functions.testpredict(roi_detect) cls_scores = pingit.predict(roi_detect)[0] #print(cls_scores) ind = np.argmax(cls_scores) if (ind == 1): zabri = 1 pos += 1 #cv2.imshow("pos", img) #cv2.waitKey() positive_props.append(prop) #bb,lm = common_functions.rescale_detections_to_full_image(bb,lm, prop) #detection = [bb,lm] #detections_regressed.append(detection) ious = eval_functions.get_iou_totals_per_image(gtobjects, positive_props, images_folder + image) ##shoulder_precisions = eval_functions.get_shoulder_precisions(gtobjects, detections_regressed) # iou_props_total += ious[0] iou_detections_total += ious[1] total_gt += ious[0] total_tp += ious[1] total_fp += ious[2] if (ious[0] != 0 and ious[1] != 0): master_count += 1 recall = total_tp / total_gt miss_rate = total_fp / (total_tp + total_fp) #av_pckh_precision = total_pckh_precision/(master_count) data['results'].append({ 'at': str(index), 'recall': recall, 'miss_rate': miss_rate }) with open( config.results_out + config.mtcnn_model + config.bbox_loss + ".json", 'a') as outfile: json.dump(data, outfile, indent=4) return recall, miss_rate
def evaluate_3c(pingit, images_folder): images_folder = "/Data2TB/correctly_registered/S12/test/depth/" images = [ f for f in listdir(images_folder) if isfile(join(images_folder, f)) ] jsonprop = "/Data2TB/correctly_registered/S12/test/output.json" jsongt = "/Data2TB/sample/annotations.json" list_thresholds = [ 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9 ] percentage = 0.5 list_precisions = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] list_recalls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] list_gt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_gt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_tn = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_tp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_fp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_outl = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_fn = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_pckh_precision = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] total_true_detections_p5 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] iou_props_total = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] iou_detections_total = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] master_count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] av_iou_prop = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] av_iou_detection = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] recall = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] miss_rate = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] precision = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] av_pckh_precision = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for image in images: total_proposals = 0 #image = images[i] positive_props = [] detections_regressed = [] img = cv2.imread(images_folder + image, -1) proposals, gtobjects = common_functions.get_proposal_and_gt_boxes_mod( image, jsonprop, jsongt) count = 0 propcount = 0 list_positive_props = [[], [], [], [], [], [], [], [], [], [], [], [], [], []] list_detections_regressed = [[], [], [], [], [], [], [], [], [], [], [], [], [], []] for prop in proposals: total_proposals += 1 imgtemp = img.copy() #cv2.imshow("tmp",imgtemp) #cv2.waitKey() xmin = prop[0][0] ymin = prop[0][1] xmax = prop[0][2] ymax = prop[0][3] headpoint = prop[1] xmin, ymin, xmax, ymax = common_functions.refine_bounding_box( xmin, ymin, xmax, ymax) roi = imgtemp[ymin:ymax, xmin:xmax] x_roi = headpoint[0] - xmin y_roi = headpoint[1] - ymin headpoint_roi = [y_roi, x_roi] roi = mod.get_channels(roi, headpoint_roi) # #roi1copy = roi1.copy() encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 95] result, encimg = cv2.imencode('.jpg', roi, encode_param) roi = cv2.imdecode(encimg, 1) width_original = roi.shape[1] roi_detect = cv2.resize(roi, (48, 48)) roi_detect = roi_detect.reshape(1, 48, 48, 3) roi_detect = (roi_detect.astype('float32') - 127.5) / 128 roi_detect = roi_detect[..., ::-1] cls_scores = pingit.predict(roi_detect)[0] for i in range(len(list_thresholds)): if (cls_scores[0][1] >= list_thresholds[i]): list_positive_props[i].append(prop) #bbtmp,lmtmp = common_functions.rescale_detections_to_full_image(bb,lm, prop) #list_detections_regressed[i].append([bbtmp,lmtmp]) for i in range(len(list_thresholds)): results = get_iou_totals_per_image(gtobjects, list_positive_props[i], images_folder + image, percentage) iou_props_total[i] += results[0] iou_detections_total[i] += results[1] total_gt[i] += results[2] total_tp[i] += results[3] total_fp[i] += results[4] total_outl[i] += results[6] total_fn[i] += results[7] total_tn[ i] += total_proposals - results[3] - results[4] - results[6] total_pckh_precision[i] += results[5] total_true_detections_p5[i] += results[8] #total_precisions += ious[5] if (results[0] != 0): master_count[i] += 1 for i in range(len(list_thresholds)): av_iou_prop[i] = iou_props_total[i] / master_count[i] av_iou_detection[i] = iou_detections_total[i] / master_count[i] recall[i] = total_tp[i] / total_gt[i] miss_rate[i] = total_fp[i] / (total_fp[i] + total_tn[i]) precision[i] = total_tp[i] / (total_tp[i] + total_fp[i]) av_pckh_precision[i] = total_pckh_precision[i] / (master_count[i]) #recall[i] = total_tp[i] / total_gt[i] #precision[i] = total_tp[i] / (total_tp[i] + total_fp[i]) print("Threshold: ", round(list_thresholds[i], 2)) #print("Average prop IOU: " , round(av_iou_prop[i],2)) #print("Average detection IOU: " , round(av_iou_detection[i],2)) #print("PCKH: " , round(av_pckh_precision[i],2)) print("Recall: ", round(recall[i], 2)) print("Precision: ", round(precision[i], 2)) print("") print("") return av_iou_detection, recall, miss_rate, av_pckh_precision, av_iou_prop