mmrotate学习(5)mmrotate测试训练好的模型map

该博客介绍了如何在mmrotate框架下测试模型在IoU阈值75下的mAP,以及计算0.05到0.95范围内IoU的平均mAP。首先,需要修改dota.py和test.py的参数,包括设置IoU阈值和配置文件路径。然后,利用DOTA_devkit提供的evaluation.py计算不同IoU下的平均mAP,并通过ResultMerge_multi_process.py处理预测结果。最后,通过test.py运行测试并保存结果,再调用evalution()函数评估性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

测试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
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值