Skip to content

Commit

Permalink
Return dir_ in dir_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya-mohammadi committed Sep 1, 2023
1 parent aa3ec14 commit d54bfc4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 69 deletions.
2 changes: 1 addition & 1 deletion deep_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

# Deep Utils version number
__version__ = "1.2.4"
__version__ = "1.2.5"

# no third-party python libraries are required for the following classes
_import_structure = {
Expand Down
136 changes: 69 additions & 67 deletions deep_utils/utils/dir_utils/dir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@


def transfer_directory_items(
in_dir,
out_dir,
transfer_list,
mode="cp",
remove_out_dir=False,
skip_transfer=False,
remove_in_dir=False,
in_dir,
out_dir,
transfer_list,
mode="cp",
remove_out_dir=False,
skip_transfer=False,
remove_in_dir=False,
):
"""
Expand Down Expand Up @@ -61,18 +61,18 @@ def transfer_directory_items(


def dir_train_test_split(
in_dir,
train_dir="./train",
val_dir="./val",
test_size=0.1,
mode="cp",
remove_out_dir=False,
skip_transfer=False,
remove_in_dir=False,
skip_error=True,
ignore_list: List[str] = None,
logger=None,
verbose=1
in_dir,
train_dir="./train",
val_dir="./val",
test_size=0.1,
mode="cp",
remove_out_dir=False,
skip_transfer=False,
remove_in_dir=False,
skip_error=True,
ignore_list: List[str] = None,
logger=None,
verbose=1
):
"""
Expand Down Expand Up @@ -128,13 +128,13 @@ def dir_train_test_split(


def split_dir_of_dir(
in_dir,
train_dir="./train",
val_dir="./val",
test_size=0.1,
mode="cp",
remove_out_dir=False,
remove_in_dir=False,
in_dir,
train_dir="./train",
val_dir="./val",
test_size=0.1,
mode="cp",
remove_out_dir=False,
remove_in_dir=False,
):
"""
Expand Down Expand Up @@ -179,17 +179,17 @@ def split_dir_of_dir(


def split_xy_dir(
x_in_dir,
y_in_dir,
x_train_dir="train/samples",
y_train_dir="train/targets",
x_val_dir="val/samples",
y_val_dir="val/targets",
mode="cp",
val_size=0.1,
skip_transfer=False,
remove_out_dir=False,
remove_in_dir=False,
x_in_dir,
y_in_dir,
x_train_dir="train/samples",
y_train_dir="train/targets",
x_val_dir="val/samples",
y_val_dir="val/targets",
mode="cp",
val_size=0.1,
skip_transfer=False,
remove_out_dir=False,
remove_in_dir=False,
):
train_names, val_names = dir_train_test_split(
x_in_dir,
Expand Down Expand Up @@ -223,12 +223,12 @@ def split_xy_dir(


def crawl_directory_dataset(
dir_: str,
ext_filter: list = None,
map_labels=False,
label_map_dict: dict = None,
logger=None,
verbose=1,
dir_: str,
ext_filter: list = None,
map_labels=False,
label_map_dict: dict = None,
logger=None,
verbose=1,
) -> Union[Tuple[List[str], List[int]], Tuple[List[str], List[int], Dict]]:
"""
crawls a directory of classes and returns the full path of the items paths and their class names
Expand Down Expand Up @@ -282,7 +282,7 @@ def crawl_directory_dataset(
return x, y


def remove_create(dir_, remove=True, logger=None, verbose=1):
def remove_create(dir_: str, remove=True, logger=None, verbose=1):
"""
Removes and creates the input directory!
:param dir_:
Expand All @@ -299,6 +299,8 @@ def remove_create(dir_, remove=True, logger=None, verbose=1):
if dir_:
os.makedirs(dir_, exist_ok=True)
log_print(logger, f"Successfully removed and created dir: {dir_}", verbose=verbose)
return dir_
raise ValueError("dir_ should be provided!")


def mkdir_incremental(dir_path: str, base_name="exp", fix_name=None, overwrite=False) -> Path:
Expand Down Expand Up @@ -367,16 +369,16 @@ def file_incremental(file_path, artifact_type="prefix", artifact_value=0, extra_


def cp_mv_all(
input_dir,
res_dir,
mode="cp",
filter_ext: Union[list, tuple, str, None] = None,
artifact_type="prefix",
artifact_value=0,
extra_punctuation="_",
add_artifact_value=False,
logger=None,
verbose=1,
input_dir,
res_dir,
mode="cp",
filter_ext: Union[list, tuple, str, None] = None,
artifact_type="prefix",
artifact_value=0,
extra_punctuation="_",
add_artifact_value=False,
logger=None,
verbose=1,

):
"""
Expand Down Expand Up @@ -409,19 +411,19 @@ def cp_mv_all(


def split_segmentation_dirs(
in_images,
in_masks,
out_train="./train",
out_val="./val",
image_dir_name="images",
mask_dir_name="masks",
img_ext=None,
mask_ext=None,
mode="cp",
test_size=0.2,
remove_out_dir=False,
remove_in_dir=False,
skip_transfer=False,
in_images,
in_masks,
out_train="./train",
out_val="./val",
image_dir_name="images",
mask_dir_name="masks",
img_ext=None,
mask_ext=None,
mode="cp",
test_size=0.2,
remove_out_dir=False,
remove_in_dir=False,
skip_transfer=False,
):
from sklearn.model_selection import train_test_split

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.2.4"
VERSION = "1.2.5"

long_description = open("Readme.md", mode="r", encoding="utf-8").read()

Expand Down

0 comments on commit d54bfc4

Please sign in to comment.