import numpy as np
import os
import os.path as osp
import json
def get_josn_by_filename(josn_file_path):
with open(json_file_path) as f:
json_data = json.load(f)
f1 = json_data["annotation"]
f2 = f1["face"]
if f2 == []:
return []
return f2[0]["box"]
def get_josn_by_filename1(josn_file_path):
with open(json_file_path) as f:
json_data = json.load(f)
return json_data
def iou(box1,box2):
x0,y0,x1,y1 = box1
x2,y2,x3,y3,score = box2
s1 = (x1-x0)*(y1-y0)
s1 = (x3-x2)*(y3-y2)
w = max(0,min(x1,x3) - max(x0,x2))
h = max(0,min(y1,y3) - max(y0,y2))
inter = w*h
iou = inter/(s1+s2-inter)
return iou
if__name__=='__main__':
p = 0
r = 0
tp = 0-
psum = 0
fp = 0
setscore = 0.9
#0.05-0.95
path1 = R''
path2 = R''
for root,dirs,files in os.walk(path1):
for file in files:
file_name = os.path.join(root,file)
filelist = get_json_by_filename(file_name)
file_rfind = file_name.rfind('\\')
filename = file_name[file_rfind + 1:]
box1 = filelist
for root1,dirs1,files1 in os.walk(path2) :
for file1 in files1:
file_name1 = os.path.join(root1,file1)
file_rfind1 = file_name1.rfind('\\')
filename1 = file_name1[file_rfind1 + 1:]
if filename1 = filename:
filelist1 = get_json_by_filename1(file_name1)
box2 = filelist1
psum = psum + 1
print(filename1)
if box1 != [] :
value = iou(box1,box2)
path3 = R''
scorelist = get_json_by_filename1(path3)
score = scorellist[0]
if score >= setscore :
if box1 != []:
if value >= 0.5:
#人脸检测顾iou设为0.5
tp = tp+1
if value < 0.5:
fp = fp + 1
if box1 == [] and box2 != [] :
fp = fp + 1
if filename1 = 'endfilename' :
p = tp/(tp+fp)
r = tp/psum
print(psum)
print(p)
print(r) `
PR求法(包含IOU求法)
最新推荐文章于 2023-11-05 21:53:05 发布