Skip to content

Instantly share code, notes, and snippets.

@elranu
Created August 7, 2018 12:08
Show Gist options
  • Save elranu/40bc952fadf62175c218724f98a7428e to your computer and use it in GitHub Desktop.
Save elranu/40bc952fadf62175c218724f98a7428e to your computer and use it in GitHub Desktop.
to yolo
import re
with open("labels_imagenes.csv", "r") as inp:
content = inp.read()
out = open('algo.csv', 'a')
out_dict = dict()
for line in content.split('\n')[1:-1]:
file, x, y, w, h, class_id = tuple(*re.findall(r'"(.+?),.+?x""""\:(\d+?)\b.+?y""""\:(\d+?)\b.+width"""":(\d+?)\b.+height"""":(\d+?)\b.+?idf"""":""""(.+?)"', line))
xmax = int(x) + int(w)
ymax = int(y) + int(h)
object = f'{x},{y},{xmax},{ymax},{class_id}'
if file in out_dict:
out_dict[file].append(object)
else:
out_dict[file] = [object]
for k, v in out_dict.items():
out.write(f'{k} {" ".join(v)}\n')
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment