代码拉取完成,页面将自动刷新
"""
计算ap
"""
from settings import gt_path, pic_file_path
import os
from query import query_picture
import xlwt
def compute_one_ap(classes):
ranked_list = load_list('rank_list.txt')
good_ls = load_list(gt_path + '\\' + classes+'good.txt')
ok_ls = load_list(gt_path + '\\' + classes + 'ok.txt')
junk_ls = load_list(gt_path + '\\' + classes + 'junk.txt')
pos_ls = good_ls + ok_ls
return compute_ap(pos_ls, junk_ls, ranked_list)
def compute_ap(pos, amb, ranked_list):
ap = 0
ap_ls = []
for j in range(10):
for i in range(j+1):
if ranked_list[i] in amb:
continue
elif ranked_list[i] in pos:
ap += 1
ap_ls.append(ap*100/(j+1))
print('top', j+1, ':', ap*100/(j+1), sep='')
ap = 0
return ap_ls
def load_list(path):
with open(path, 'r') as f:
data = f.readlines()
return data
def main():
rootdir = gt_path # gt文件夹路径
magins_path = pic_file_path # 图形库文件夹路径
excelf = xlwt.Workbook()
sheet1 = excelf.add_sheet(u'sheet1', cell_overwrite_ok=True)
n = 0
for dirpath, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
if filename.split('.')[0][-5:] == 'query':
classes = filename.split('.')[0][:-5]
with open(rootdir + '\\' + filename) as f:
pic_name = f.read().split(' ')[0][5:]
pic_path = magins_path + '\\' + pic_name + '.jpg'
query_picture(pic_path, 10)
ap_ls = compute_one_ap(classes)
for i in range(len(ap_ls)):
sheet1.write(n, i, ap_ls[i])
n += 1
excelf.save('ap.xls')
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。