YOLOv4-pytorch icon indicating copy to clipboard operation
YOLOv4-pytorch copied to clipboard

python3 utils/get_map.py

Open lilangyi opened this issue 4 years ago • 8 comments

执行了这个为什么只有map的图片,没有PR曲线呢?要如何获取PR曲线,感谢!

lilangyi avatar Jan 24 '21 10:01 lilangyi

They should in the same folder https://github.com/argusswift/YOLOv4-pytorch/blob/158ea9223cb57f88d81f60dd894b7be9f1a285f8/utils/get_map.py#L949

jingtianyilong avatar Jan 25 '21 02:01 jingtianyilong

他们应该在同一个文件夹里 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)

cymdhx avatar Jan 25 '21 11:01 cymdhx

(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

jingtianyilong avatar Jan 26 '21 01:01 jingtianyilong

这里的问题是因为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)

li-ju-bazhong avatar May 06 '21 11:05 li-ju-bazhong

我重写了个把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文件夹相同的目录下即可

li-ju-bazhong avatar May 06 '21 14:05 li-ju-bazhong

我重写了个把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文件夹相同的目录下即可

微信截图_20210522155330 现在生成的是这样的文件,很奇怪

sjfei avatar May 22 '21 07:05 sjfei

我重写了个把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文件夹相同的目录下即可

微信截图_20210522155330 现在生成的是这样的文件,很奇怪

请问大佬解决了么?

我也是生成的类似的txt文件(第一个图),使用上面大佬给的转换代码也出现了错误(第二个图) 屏幕截图 2021-05-26 221556 屏幕截图 2021-05-26 221624

wasedd avatar May 26 '21 14:05 wasedd

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')

metacarbon avatar Oct 21 '21 08:10 metacarbon