Skip to content

Commit

Permalink
OpCond and knight sample ids (#191)
Browse files Browse the repository at this point in the history
Co-authored-by: Moshe Raboh [email protected] <[email protected]>
  • Loading branch information
mosheraboh and Moshe Raboh [email protected] authored Oct 11, 2022
1 parent 060abd2 commit 9e46921
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
10 changes: 3 additions & 7 deletions fuse/data/datasets/caching/samples_cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ def delete_cache(self) -> None:
print("---- list end ----")
print("deleting ... ")
for del_dir in dirs_to_delete:
print(f"deleting {del_dir} ...")
all_found = glob(os.path.join(del_dir, "hash_*"))
for found in all_found:
if not os.path.isdir(found):
continue
delete_directory_tree(found)
print(f"deleting {os.path.abspath(del_dir)} ...")
delete_directory_tree(del_dir)

def _get_write_dir(self):
ans = self._write_dir_logic(self._cache_dirs)
Expand Down Expand Up @@ -175,7 +171,7 @@ def cache_samples(self, orig_sample_ids: List[Any]) -> List[Tuple[str, Union[Non
for curr_read_dir in read_dirs:
fullpath_filename = os.path.join(curr_read_dir, "full_sets_info", hash_filename)
if os.path.isfile(fullpath_filename):
print(f"entire samples set {hash_filename} already cached. Found {fullpath_filename}")
print(f"entire samples set {hash_filename} already cached. Found {os.path.abspath(fullpath_filename)}")
return load_pickle(fullpath_filename)

orig_sid_to_final = OrderedDict()
Expand Down
22 changes: 22 additions & 0 deletions fuse/data/ops/ops_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,25 @@ class OpZScoreNorm(OpBase):
def __call__(self, sample_dict: NDict, key: str, mean: float, std: float):
sample_dict[key] = (sample_dict[key] - mean) / std
return sample_dict


class OpCond(OpBase):
"""Apply given op if the condition (either directly specified or read from the sample_dict) is True"""

def __init__(self, op: OpBase):
"""
:param op: the op to apply
"""
super().__init__()
self._op = op

def __call__(self, sample_dict: NDict, condition: Union[str, bool], **kwargs) -> Union[None, dict, List[dict]]:
"""
:param condition:instruct if to call the inner op. Can either a boolean or a key to sample_dict used to extract the boolean
"""
if isinstance(condition, str):
condition = sample_dict[condition]
if condition:
return self._op(sample_dict, **kwargs)
else:
return sample_dict
2 changes: 1 addition & 1 deletion fuse/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.4"
__version__ = "0.2.5"
2 changes: 1 addition & 1 deletion fuseimg/datasets/knight.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def sample_ids(path: str) -> list:
get all the sample ids in train-set
sample_id is directory file named case_xxxxx found in the specified path
"""
files = [f for f in glob(os.path.join(path, "data/case_*"))]
files = [os.path.basename(f) for f in glob(os.path.join(path, "case_*"))]
return files

@staticmethod
Expand Down

0 comments on commit 9e46921

Please sign in to comment.