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