MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / increment_path

Function increment_path

SwissArmyTransformer/examples/yolos/infer_util.py:124–138  ·  view source on GitHub ↗
(path, exist_ok=False, sep='', mkdir=False)

Source from the content-addressed store, hash-verified

122 print(f"{fname} saved.")
123
124def increment_path(path, exist_ok=False, sep='', mkdir=False):
125 # Increment file or directory path, i.e. runs/exp --> runs/exp{sep}2, runs/exp{sep}3, ... etc.
126 path = Path(path) # os-agnostic
127 if path.exists() and not exist_ok:
128 suffix = path.suffix
129 path = path.with_suffix('')
130 dirs = glob.glob(f"{path}{sep}*") # similar paths
131 matches = [re.search(rf"%s{sep}(\d+)" % path.stem, d) for d in dirs]
132 i = [int(m.groups()[0]) for m in matches if m] # indices
133 n = max(i) + 1 if i else 2 # increment number
134 path = Path(f"{path}{sep}{n}{suffix}") # update path
135 dir = path if path.suffix == '' else path.parent # directory
136 if not dir.exists() and mkdir:
137 dir.mkdir(parents=True, exist_ok=True) # make directory
138 return path
139
140def save_pred_fig(output_dir, output_dic, keep):
141 # im = Image.open(os.path.join(output_dir, "img.png"))

Callers 1

infer_util.pyFile · 0.85

Calls 1

existsMethod · 0.80

Tested by

no test coverage detected