Skip to content

Commit 782a659

Browse files
committed
Update input parameter
1 parent b94288d commit 782a659

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

label_convert/coco_to_labelImg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class COCOTolabelImg:
1717
def __init__(self, data_dir: ValueType = None, save_dir: ValueType = None):
18+
if data_dir is None:
19+
raise ValueError("data_dir must not be None")
20+
1821
self.data_dir = Path(data_dir)
1922
self.verify_exists(self.data_dir)
2023

label_convert/darknet_to_coco.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def __init__(
2020
data_dir: ValueType = None,
2121
save_dir: ValueType = None,
2222
):
23+
if data_dir is None:
24+
raise ValueError("data_dir must not be None")
25+
2326
self.data_dir = Path(data_dir)
2427
self.verify_exists(self.data_dir)
2528

label_convert/labelImg_to_publaynet.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def __init__(
2323
have_test: bool = True,
2424
test_ratio: float = 0.2,
2525
):
26+
if data_dir is None:
27+
raise ValueError("data_dir must not be None")
28+
2629
self.data_dir = Path(data_dir)
2730
self.verify_exists(data_dir)
2831

@@ -132,7 +135,7 @@ def generate_json(
132135
label_path = img_path.with_name(f"{img_path.stem}.txt")
133136
try:
134137
label_datas = self.read_txt(label_path)
135-
except Exception as e:
138+
except Exception:
136139
print(f"{label_path} meets error.")
137140
continue
138141

@@ -204,16 +207,17 @@ def mkdir(dir_path: Union[Path, str]) -> None:
204207

205208
def main():
206209
parser = argparse.ArgumentParser()
207-
parser.add_argument(
208-
"--data_dir", type=str, required=True, help="The directory from labelImg."
209-
)
210+
parser.add_argument("--data_dir", type=str, default=None)
211+
parser.add_argument("--save_dir", type=str, default=None)
210212
parser.add_argument("--val_ratio", type=float, default=0.2)
211213
parser.add_argument("--have_test", action="store_true", default=False)
212214
parser.add_argument("--test_ratio", type=float, default=0.2)
213215
args = parser.parse_args()
214216

215-
converter = LabelImgToPubLayNet(args.val_ratio, args.have_test, args.test_ratio)
216-
converter(args.data_dir)
217+
converter = LabelImgToPubLayNet(
218+
args.data_dir, args.save_dir, args.val_ratio, args.have_test, args.test_ratio
219+
)
220+
converter()
217221
print(f"Successfully output to the {args.out_dir}")
218222

219223

label_convert/labelImg_to_yolov5.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def __init__(
2222
have_test: bool = False,
2323
test_ratio: float = 0.2,
2424
):
25+
if data_dir is None:
26+
raise ValueError("data_dir must not be None")
27+
2528
self.data_dir = Path(data_dir)
2629
self.verify_exists(self.data_dir)
2730

label_convert/labelme_to_coco.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import shutil
88
import time
99
from pathlib import Path
10-
from typing import List, Optional, Union
10+
from typing import Union
1111

1212
import numpy as np
1313
from tqdm import tqdm
@@ -16,7 +16,6 @@
1616

1717

1818
class LabelmeToCOCO:
19-
2019
def __init__(
2120
self,
2221
data_dir: ValueType = None,
@@ -25,7 +24,10 @@ def __init__(
2524
have_test: bool = False,
2625
test_ratio: float = 0.2,
2726
):
27+
if data_dir is None:
28+
raise ValueError("data_dir must not be None")
2829
self.data_dir = Path(data_dir)
30+
self.verify_exists(self.data_dir)
2931

3032
self.val_ratio = val_ratio
3133
self.test_ratio = test_ratio

label_convert/yolov5_to_coco.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
class YOLOV5ToCOCO:
2020
def __init__(self, data_dir: ValueType = None, save_dir: ValueType = None):
21+
if data_dir is None:
22+
raise ValueError("data_dir must not be None")
2123
self.data_dir = Path(data_dir)
22-
24+
self.verify_exists(self.data_dir)
2325
self.verify_exists(self.data_dir / "images")
2426
self.verify_exists(self.data_dir / "labels")
2527

0 commit comments

Comments
 (0)