Skip to content

Commit

Permalink
Update input parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Mar 30, 2024
1 parent b94288d commit 782a659
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions label_convert/coco_to_labelImg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class COCOTolabelImg:
def __init__(self, data_dir: ValueType = None, save_dir: ValueType = None):
if data_dir is None:
raise ValueError("data_dir must not be None")

self.data_dir = Path(data_dir)
self.verify_exists(self.data_dir)

Expand Down
3 changes: 3 additions & 0 deletions label_convert/darknet_to_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(
data_dir: ValueType = None,
save_dir: ValueType = None,
):
if data_dir is None:
raise ValueError("data_dir must not be None")

self.data_dir = Path(data_dir)
self.verify_exists(self.data_dir)

Expand Down
16 changes: 10 additions & 6 deletions label_convert/labelImg_to_publaynet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def __init__(
have_test: bool = True,
test_ratio: float = 0.2,
):
if data_dir is None:
raise ValueError("data_dir must not be None")

self.data_dir = Path(data_dir)
self.verify_exists(data_dir)

Expand Down Expand Up @@ -132,7 +135,7 @@ def generate_json(
label_path = img_path.with_name(f"{img_path.stem}.txt")
try:
label_datas = self.read_txt(label_path)
except Exception as e:
except Exception:
print(f"{label_path} meets error.")
continue

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

def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--data_dir", type=str, required=True, help="The directory from labelImg."
)
parser.add_argument("--data_dir", type=str, default=None)
parser.add_argument("--save_dir", type=str, default=None)
parser.add_argument("--val_ratio", type=float, default=0.2)
parser.add_argument("--have_test", action="store_true", default=False)
parser.add_argument("--test_ratio", type=float, default=0.2)
args = parser.parse_args()

converter = LabelImgToPubLayNet(args.val_ratio, args.have_test, args.test_ratio)
converter(args.data_dir)
converter = LabelImgToPubLayNet(
args.data_dir, args.save_dir, args.val_ratio, args.have_test, args.test_ratio
)
converter()
print(f"Successfully output to the {args.out_dir}")


Expand Down
3 changes: 3 additions & 0 deletions label_convert/labelImg_to_yolov5.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def __init__(
have_test: bool = False,
test_ratio: float = 0.2,
):
if data_dir is None:
raise ValueError("data_dir must not be None")

self.data_dir = Path(data_dir)
self.verify_exists(self.data_dir)

Expand Down
6 changes: 4 additions & 2 deletions label_convert/labelme_to_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shutil
import time
from pathlib import Path
from typing import List, Optional, Union
from typing import Union

import numpy as np
from tqdm import tqdm
Expand All @@ -16,7 +16,6 @@


class LabelmeToCOCO:

def __init__(
self,
data_dir: ValueType = None,
Expand All @@ -25,7 +24,10 @@ def __init__(
have_test: bool = False,
test_ratio: float = 0.2,
):
if data_dir is None:
raise ValueError("data_dir must not be None")
self.data_dir = Path(data_dir)
self.verify_exists(self.data_dir)

self.val_ratio = val_ratio
self.test_ratio = test_ratio
Expand Down
4 changes: 3 additions & 1 deletion label_convert/yolov5_to_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

class YOLOV5ToCOCO:
def __init__(self, data_dir: ValueType = None, save_dir: ValueType = None):
if data_dir is None:
raise ValueError("data_dir must not be None")
self.data_dir = Path(data_dir)

self.verify_exists(self.data_dir)
self.verify_exists(self.data_dir / "images")
self.verify_exists(self.data_dir / "labels")

Expand Down

0 comments on commit 782a659

Please sign in to comment.