Comments (8)
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)
from weighted-boxes-fusion.
你好,请问你解决了吗?
from weighted-boxes-fusion.
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?
from weighted-boxes-fusion.
你好,请问你解决了吗?
之后要怎么做呢,从保存好的out_file 中读取数据使用你们的wbf;
请问有从两个csv文件里读取框坐标后使用wbf的demo吗
from weighted-boxes-fusion.
之后要怎么做呢,从保存好的out_file 中读取数据使用你们的wbf;
请问有从两个csv文件里读取框坐标后使用wbf的demo吗
from weighted-boxes-fusion.
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?
from weighted-boxes-fusion.
Hello friends,csv file i have made,then how to use wbf ?thanks for your reply
from weighted-boxes-fusion.
之后要怎么做呢,从保存好的out_file 中读取数据使用你们的wbf; 请问有从两个csv文件里读取框坐标后使用wbf的demo吗
哥们你现在解决了吗?可以请教一下?
from weighted-boxes-fusion.
Related Issues (20)
- Incorrect conf_type='max' mode HOT 1
- Strange result if boxes are intersected inside one model HOT 2
- confidence score > 1 issue HOT 1
- Bbox is 'Nan' when weights have 0 HOT 4
- How to find the optimal hyper-parameters in the ensembling process HOT 6
- Can work with polygon object ? HOT 1
- Compatibility for Instance Segmentation HOT 1
- Building wheel for llvmlite ... error HOT 1
- How to use in Yolov5
- Implemetation on mobile phone HOT 4
- label list on SSD HOT 1
- run NMS on empty bounding box from one of ensembled models HOT 5
- Single instance NMS
- 2d bbox wbf compute result error
- Is WBF consider to be part of Ensemble Learning HOT 4
- Back propagation when multiple models are ensembled
- model fusion for rotating boxes
- Recall and Confusion matrix, also the confusion matrix, of the WBF HOT 5
- about map_boxes in run_benchmark_oid.py HOT 2
- AttributeError: module 'numpy' has no attribute 'str'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from weighted-boxes-fusion.