-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use it in yolov5? #37
Comments
你好,请问你解决了吗? |
I used it in Yolov5. What you need to do is to read all txt files with predictions created by Yolo and gather it in single CSV file or just numpy table. Then you can use WBF. Here is my code: # coding: utf-8
__author__ = 'ZFTurbo: https://kaggle.com/zfturbo'
import glob
import os
def convert_yolov5_preds(valid_files_dir, labels_dir, out_file):
valid_files = glob.glob(valid_files_dir + '*.jpg')
print('Total image files: {}'.format(len(valid_files)))
files = glob.glob(labels_dir + '*.txt')
print('Total labels files: {}'.format(len(files)))
valid_ids = [os.path.basename(f)[:-4] for f in valid_files]
out = open(out_file, 'w')
out.write('image_id,label,conf,x1,x2,y1,y2\n')
fixes = 0
for f in files:
image_id = os.path.basename(f)[:-4]
in1 = open(f, 'r')
lines = in1.readlines()
in1.close()
valid_ids.remove(image_id)
for line in lines:
arr = line.strip().split(' ')
class_id = arr[0]
x = float(arr[1])
y = float(arr[2])
w = float(arr[3])
h = float(arr[4])
x1 = x - (w / 2)
x2 = x + (w / 2)
y1 = y - (h / 2)
y2 = y + (h / 2)
if x1 < 0:
fixes += 1
x1 = 0
if x2 > 1:
fixes += 1
x2 = 1
if y1 < 0:
fixes += 1
y1 = 0
if y2 > 1:
fixes += 1
y2 = 1
conf = arr[5]
pred_str = '{},{},{},{:.6f},{:.6f},{:.6f},{:.6f}\n'.format(image_id, str(class_id), conf, x1, x2, y1, y2)
out.write(pred_str)
print(len(valid_ids))
# Output empty IDs
for image_id in list(valid_ids):
out.write('{},,,,,,\n'.format(image_id))
out.close()
print('Fixes: {}'.format(fixes))
print('Result was written in: {}'.format(out_file))
if __name__ == '__main__':
# Location of images
valid_files_dir = './valid_imgs/'
# Location of yolo v5 predictions
labels_dir = 'yolov5x/valid_iou_0.45_02.1/labels/'
# CSF-file to store results
out_file = 'yolov5x_full_valid_iou_0.45_0.1.csv'
convert_yolov5_preds(valid_files_dir, labels_dir, out_file) |
then? |
之后要怎么做呢,从保存好的out_file 中读取数据使用你们的wbf; |
之后要怎么做呢,从保存好的out_file 中读取数据使用你们的wbf; |
Please, I have used WBF in Yolov5.Dataset is coco128.Device is GPU-1050ti .But the post processing time of every image is closely 1.5s. The time is normally? |
Hello friends,csv file i have made,then how to use wbf ?thanks for your reply |
哥们你现在解决了吗?可以请教一下? |
Is the result after NMS in YoloV5 passed to WBF for secondary screening?@ZFTurbo
The text was updated successfully, but these errors were encountered: