测试map
上一篇训练教程mmrotate框架训练数据集,选用的iou=50,
我想测试iou在75之下的map的值,和iou在0.05-0.95递增的情况的平均map,需要进行以下操作:
测试AP75
1.修改mmrotate/datasets/dota.py
主要有一个参数:
1)iou_thr: iou阈值,修改成75
2.修改 test.py 中的参数
主要有三个参数:
1)config: 使用的模型文件 ;
2)checkpoint:训练得到的模型权重文件;
3)show-dir: 预测结果存放的路径
补充:测试用的数据集就是训练的步骤4中的数据集路径
3.输入指令
python test.py --eval mAP
测试AP(iou在0.05-0.95递增的情况的平均map)
需要借助其他的代码
1.修改mmrotate/datasets/dota.py
在类class DOTADataset(CustomDataset)下添加以下子函数
def save_dota_txt(self, results, outfolder,conf_thresh=0.01):
import math
if not os.path.exists(outfolder):
os.mkdir(outfolder)
for i in range(len(self)):
imgname = self.data_infos[i]['filename']
bboxresult = results[i]
txt_name = os.path.join(outfolder,imgname.split('.')[0]+'.txt')
f = open(txt_name, 'w')
for cls, bboxes in zip(self.CLASSES, bboxresult):
for box in bboxes:
if box[-1] < conf_thresh:
continue
xc, yc, w, h, ag, score = box.tolist()
wx, wy = w / 2 * math.cos(ag), w / 2 * math.sin(ag)
hx, hy = -h / 2 * math.sin(ag), h / 2 * math.cos(ag)
p1 = (xc - wx - hx, yc - wy - hy)
p2 = (xc + wx - hx, yc + wy - hy)
p3 = (xc + wx + hx, yc + wy + hy)
p4 = (xc - wx + hx, yc - wy + hy)
ps = (np.concatenate([p1, p2, p3, p4]))
points = ' '.join(ps.astype(float).astype(str))
# soft label and eval result
f.write(points + ' ' + cls + ' ' + str(box[-1]) + '\n')
# hard label
# if float(box[-1]) > 0.1:
# f.write(points + ' ' + cls + ' 0\n')
f.close()
2.借用evaluation.py,修改map步长
import numpy as np
import os
from shapely.geometry import Polygon
import sys
sys.path.append('/home/disk/bing/mmrotate-main/DOTA_devkit')
import polyiou
def parse_gt(filename):
"""
:param filename: ground truth file to parse
:return: all instances in a picture
"""
objects = []
with open(filename, 'r') as f:
while True:
line = f.readline()
if line:
splitlin