From 9d132ee26d392c9cf2546c2cdbc200f122bd9235 Mon Sep 17 00:00:00 2001 From: Zerohertz Date: Tue, 4 Apr 2023 21:23:05 +0900 Subject: [PATCH] :memo: Update: labelme to YOLOv5 --- labelme2YOLOv5.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/labelme2YOLOv5.py b/labelme2YOLOv5.py index d5332d0..bcbd036 100644 --- a/labelme2YOLOv5.py +++ b/labelme2YOLOv5.py @@ -36,15 +36,12 @@ def labelme2YOLOv5(target, relJson): with open(relJson) as f: data = json.load(f) for i in range(len(data['shapes'])): - tmp = data['shapes'][i]['points'] + tmp = data['shapes'][i]['points'] tar = [] cnt = 0 for j in tmp: - for k in j: - if cnt % 2 == 0: - tar.append(k/w) - else: - tar.append(k/h) + tar.append(j[0]/w) + tar.append(j[1]/h) with open(targetDirLab + '/' + relJson.replace('.json', '.txt'), 'a', encoding='utf-8') as f: wr = csv.writer(f, delimiter=' ') wr.writerow([0, *tar]) @@ -68,6 +65,7 @@ def labelme2YOLOv5(target, relJson): for c in tqdm(candidate): if cnt % 3 == 0: labelme2YOLOv5('val', c) + labelme2YOLOv5('train', c) else: labelme2YOLOv5('train', c) cnt += 1