in src/prepare_data/neu.py [0:0]
def main(data_path: str, output_path: str, archived: bool = True) -> None:
"""
Data preparation
Parameters
----------
data_path : str
Raw data path
output_path : str
Output data path
archived: bool
Whether the file is archived or not (for testing)
Raises
------
ValueError
If the packed data file is different from NEU-CLS or NEU-DET
"""
data_path = Path(data_path)
if archived:
unpack(data_path)
data_path = data_path.parent / re.search(r"^[^.]*", str(data_path.name)).group(0)
try:
os.remove(str(data_path / "Thumbs.db"))
except FileNotFoundError:
print(f"Thumbs.db is not found. Continuing ...")
pass
except Exception as e:
print(f"{e}: Unknown error!")
raise e
output_path = Path(output_path)
if data_path.name == "NEU-CLS":
for cls_ in CLASSES.values():
cls_path = output_path / cls_
cls_path.mkdir(exist_ok=True)
cp_class_images(data_path, cls_, cls_path)
elif data_path.name == "NEU-DET":
for cls_ in CLASSES:
cls_path = output_path / CLASSES[cls_]
image_path = cls_path / "images"
image_path.mkdir(parents=True, exist_ok=True)
annotation_path = cls_path / "annotations"
annotation_path.mkdir(exist_ok=True)
cp_image_annotation(data_path, cls_, image_path, annotation_path)
else:
raise ValueError(f"Unknown data. Choose between `NEU-CLS` and `NEU-DET`. Given {data_path.name}")
return