YOLOv4-pytorch
YOLOv4-pytorch copied to clipboard
python3 utils/get_map.py
执行了这个为什么只有map的图片,没有PR曲线呢?要如何获取PR曲线,感谢!
They should in the same folder https://github.com/argusswift/YOLOv4-pytorch/blob/158ea9223cb57f88d81f60dd894b7be9f1a285f8/utils/get_map.py#L949
他们应该在同一个文件夹里 https://github.com/argusswift/YOLOv4-pytorch/blob/158ea9223cb57f88d81f60dd894b7be9f1a285f8/utils/get_map.py#L949
执行了这个为什么只有地图的图片,没有PR曲线呢?要如何获取PR曲线,感谢!
老哥 为什么我执行了是这样 Error. File not found: D:\YOLOv4-pytorch-master\utils\input\detection-results\000001.txt (You can avoid this error message by running extra/intersect-gt-and-dr.py)
(You can avoid this error message by running extra/intersect-gt-and-dr.py)
他们应该在同一个文件夹里 https://github.com/argusswift/YOLOv4-pytorch/blob/158ea9223cb57f88d81f60dd894b7be9f1a285f8/utils/get_map.py#L949
执行了这个为什么只有地图的图片,没有PR曲线呢?要如何获取PR曲线,感谢!
老哥 为什么我执行了是这样 Error. File not found: D:\YOLOv4-pytorch-master\utils\input\detection-results\000001.txt (You can avoid this error message by running extra/intersect-gt-and-dr.py)
(You can avoid this error message by running extra/intersect-gt-and-dr.py) check out https://github.com/Cartucho/mAP Basically, this script makes sure that your gt and your prediction image number are matching
Or you don's have GT at all. https://github.com/argusswift/YOLOv4-pytorch/blob/158ea9223cb57f88d81f60dd894b7be9f1a285f8/utils/get_map.py#L61-L62
这里的问题是因为detction-result的文件不是满足map中的验证的方式,所以导致的 Error. File not found: D:\YOLOv4-pytorch-master\utils\input\detection-results\000001.txt (You can avoid this error message by running extra/intersect-gt-and-dr.py)
我重写了个把pred_result中的文件改写的程序,写成了满足的格式,代码如下 ` import os
base_dir = 'pred_result'
cg_dir = 'detection-result'
if os.path.exists(cg_dir):
os.mkdir('detection-result')
def file_lines_to_list(path):
# open txt file lines to a list
with open(path) as f:
content = f.readlines()
# remove whitespace characters like \n
at the end of each line
content = [x.strip() for x in content]
return content
for file_name in os.listdir(base_dir): class_name = file_name.split(".txt", 1)[0] lines_list = file_lines_to_list(base_dir+'/'+file_name) for line in lines_list: img_name, confidence, left, top, right, bottom = line.split() file = open('detection-result/%s.txt' % img_name, 'a', encoding='utf-8') file.write(class_name) file.write('\t') file.write( confidence) file.write('\t') file.write(left) file.write('\t') file.write(top) file.write('\t') file.write(right) file.write('\t') file.write(bottom) file.write('\n') file.close() ` 然后把生成的detection-result文件夹粘贴到和ground-truth文件夹相同的目录下即可
我重写了个把pred_result中的文件改写的程序,写成了满足的格式,代码如下 ` import os
base_dir = 'pred_result' cg_dir = 'detection-result' if os.path.exists(cg_dir): os.mkdir('detection-result') def file_lines_to_list(path):
open txt file lines to a list
with open(path) as f: content = f.readlines()
remove whitespace characters like
\n
at the end of each linecontent = [x.strip() for x in content] return content
for file_name in os.listdir(base_dir): class_name = file_name.split(".txt", 1)[0] lines_list = file_lines_to_list(base_dir+'/'+file_name) for line in lines_list: img_name, confidence, left, top, right, bottom = line.split() file = open('detection-result/%s.txt' % img_name, 'a', encoding='utf-8') file.write(class_name) file.write('\t') file.write( confidence) file.write('\t') file.write(left) file.write('\t') file.write(top) file.write('\t') file.write(right) file.write('\t') file.write(bottom) file.write('\n') file.close() ` 然后把生成的detection-result文件夹粘贴到和ground-truth文件夹相同的目录下即可
现在生成的是这样的文件,很奇怪
我重写了个把pred_result中的文件改写的程序,写成了满足的格式,代码如下 ` import os base_dir = 'pred_result' cg_dir = 'detection-result' if os.path.exists(cg_dir): os.mkdir('detection-result') def file_lines_to_list(path):
open txt file lines to a list
with open(path) as f: content = f.readlines()
remove whitespace characters like
\n
at the end of each linecontent = [x.strip() for x in content] return content for file_name in os.listdir(base_dir): class_name = file_name.split(".txt", 1)[0] lines_list = file_lines_to_list(base_dir+'/'+file_name) for line in lines_list: img_name, confidence, left, top, right, bottom = line.split() file = open('detection-result/%s.txt' % img_name, 'a', encoding='utf-8') file.write(class_name) file.write('\t') file.write( confidence) file.write('\t') file.write(left) file.write('\t') file.write(top) file.write('\t') file.write(right) file.write('\t') file.write(bottom) file.write('\n') file.close() ` 然后把生成的detection-result文件夹粘贴到和ground-truth文件夹相同的目录下即可
现在生成的是这样的文件,很奇怪
请问大佬解决了么?
我也是生成的类似的txt文件(第一个图),使用上面大佬给的转换代码也出现了错误(第二个图)
You cannot directly apply get_map.py because the prediction result does not match the required format. I wrote a simple script to generate the txt files in the correct format described in https://github.com/Cartucho/mAP :
import os
pred_path = '/home/GitHub/YOLOv4-pytorch/pred_result'
detect_path = '/home/GitHub/YOLOv4-pytorch/detection-results'
if not os.path.exists(detect_path):
os.mkdir(detect_path)
pred_comps = os.listdir(pred_path)
for category in pred_comps:
class_name = category[:-4].split('_')[-1]
pred_txt_path = os.path.join(pred_path, category)
with open(pred_txt_path, 'r') as f:
for line in f:
img_idx, score, x_min, y_min, x_max, y_max = line.split()
with open(os.path.join(detect_path, img_idx) + '.txt', 'a') as f2:
f2.write(f'{class_name} {score} {x_min} {y_min} {x_max} {y_max}\n')