Skip to content

Commit 0fad0c3

Browse files
committed
1. Generate classes.yaml
2. Remove coco suffix in output folder.
1 parent 82c1924 commit 0fad0c3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

general_json2yolo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import contextlib
22
import json
3+
import shutil
4+
35
import yaml
46
import cv2
57
import pandas as pd
@@ -258,7 +260,7 @@ def convert_coco_json(json_dir='../coco/annotations/', use_segments=False, cls91
258260

259261
# Import json
260262
for json_file in sorted(Path(json_dir).resolve().glob('*coco*.json')):
261-
fn = Path(save_dir) / 'labels' / json_file.stem.replace('instances_', '') # folder name
263+
fn = Path(save_dir) / 'labels' / json_file.stem.replace('instances_', '').replace('_coco','') # folder name
262264
fn.mkdir()
263265
with open(json_file) as f:
264266
data = json.load(f)
@@ -322,6 +324,7 @@ def convert_coco_json(json_dir='../coco/annotations/', use_segments=False, cls91
322324

323325
with open((Path(save_dir) / json_file.stem).with_suffix('.yaml'), "w") as f:
324326
yaml.dump(yaml_dict, f)
327+
shutil.copy((Path(save_dir) / json_file.stem).with_suffix('.yaml'), (Path(save_dir) / 'classes').with_suffix('.yaml'))
325328

326329

327330
def min_index(arr1, arr2):
@@ -399,7 +402,7 @@ def delete_dsstore(path='../datasets'):
399402
source = 'COCO'
400403

401404
if source == 'COCO':
402-
convert_coco_json(r'C:\Users\1000276203\OneDrive - Western Digital\SDSS_DPAOI_CV\data\pure_dataset_memory\new chipping', # directory with *.json
405+
convert_coco_json(r'C:\Users\1000276203\OneDrive - Western Digital\SDSS_DPAOI_CV\data\new chipping', # directory with *.json
403406
use_segments=True,
404407
cls91to80=True)
405408

0 commit comments

Comments
 (0)