Darknet - 检测模型 (.weights) 计算 mAP (mean average precision)

Darknet - 检测模型 (.weights) 计算 mAP (mean average precision)

1. mAP (mean average precision) or IoU (intersect over union)

https://github.com/AlexeyAB/darknet

If training is stopped after 9000 iterations, to validate some of previous weights use this commands:
Linux
(If you use another GitHub repository, then use ./darknet detector recall... instead of ./darknet detector map...)

  • ./darknet detector map data/obj.data yolo-obj.cfg backup/yolo-obj_7000.weights
  • ./darknet detector map data/obj.data yolo-obj.cfg backup/yolo-obj_8000.weights
  • ./darknet detector map data/obj.data yolo-obj.cfg backup/yolo-obj_9000.weights

Windows
(If you use another GitHub repository, then use darknet.exe detector recall... instead of darknet.exe detector map...)

  • darknet.exe detector map data/obj.data yolo-obj.cfg backup\yolo-obj_7000.weights
  • darknet.exe detector map data/obj.data yolo-obj.cfg backup\yolo-obj_8000.weights
  • darknet.exe detector map data/obj.data yolo-obj.cfg backup\yolo-obj_9000.weights

And comapre last output lines for each weights (7000, 8000, 9000):
Choose weights-file with the highest mAP (mean average precision) or IoU (intersect over union). For example, bigger mAP gives weights yolo-obj_8000.weights - then use this weights for detection.

intersect [ˌɪntəˈsekt]:vi. 相交,交叉 vt. 横断,横切,贯穿

2. darknet_validation_command_line_detection.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Yongqiang Cheng

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

## network_resolution = 352
# network_resolution = "352"

## network_resolution = 416
# network_resolution = "416"

## network_resolution = 608
network_resolution = "608"

min_iteration = 0
gpu_index = 1
weights_file_path = "/media/famu/DISK_DATA/yongqiang/backup_******_bag"
data_file = "******_bag.data"
cfg_file = "******_bag.cfg"

command_line_base = "./darknet detector map ./cfg/%s ./cfg/%s -input_dir=.weights -i %s" % (
    data_file, cfg_file, gpu_index)


def darknet_validation_command_line(weights_file_path, command_line_base, network_resolution, min_iteration):
    weights_dir = weights_file_path + '/'
    weights_names = os.listdir(weights_dir)
    weights_names.sort()

    runsh_path_name = ("%s/%s_valid_%s.sh" % (weights_file_path, weights_file_path.split('/')[-1], network_resolution))

    runsh_fp = open(runsh_path_name, 'w')
    runsh_fp.write("#!/bin/bash" + '\n')
    runsh_fp.write('\n')

    for weights_name in weights_names:
        if ".weights" in weights_name:
            weights_name_prefix = weights_name.split('.')[0]
            weights_num = int(weights_name_prefix.split('_')[-1])

            if weights_num < min_iteration:
                continue

            target_pathname = command_line_base.replace("-input_dir=.weights", weights_dir + weights_name)
            print(target_pathname)

            runsh_fp.write(target_pathname + '\n')
        pass
    pass

    runsh_fp.write('\n')
    runsh_fp.close()


if __name__ == "__main__":
    current_directory = os.path.dirname(os.path.abspath(__file__))
    print("current_directory:", current_directory)
    darknet_validation_command_line(weights_file_path, command_line_base, network_resolution, min_iteration)

3. backup_******_bag_valid_608.sh

#!/bin/bash

./darknet detector map ./cfg/******_bag.data ./cfg/******_bag.cfg /media/famu/DISK_DATA/yongqiang/backup_******_bag/******_bag_012000.weights -i 1
./darknet detector map ./cfg/******_bag.data ./cfg/******_bag.cfg /media/famu/DISK_DATA/yongqiang/backup_******_bag/******_bag_016008.weights -i 1
./darknet detector map ./cfg/******_bag.data ./cfg/******_bag.cfg /media/famu/DISK_DATA/yongqiang/backup_******_bag/******_bag_020016.weights -i 1
......

4. bash

bash ./backup_******_bag_valid_608.sh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值