Unverified 提交 c5c647e2 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Update increment_path() to handle file paths (#2867)

上级 1df8c6c9
...@@ -591,14 +591,16 @@ def apply_classifier(x, model, img, im0): ...@@ -591,14 +591,16 @@ def apply_classifier(x, model, img, im0):
return x return x
def increment_path(path, exist_ok=True, sep=''): def increment_path(path, exist_ok=False, sep=''):
# Increment path, i.e. runs/exp --> runs/exp{sep}0, runs/exp{sep}1 etc. # Increment file or directory path, i.e. runs/exp --> runs/exp{sep}2, runs/exp{sep}3, ... etc.
path = Path(path) # os-agnostic path = Path(path) # os-agnostic
if (path.exists() and exist_ok) or (not path.exists()): if not path.exists() or exist_ok:
return str(path) return str(path)
else: else:
suffix = path.suffix
path = path.with_suffix('')
dirs = glob.glob(f"{path}{sep}*") # similar paths dirs = glob.glob(f"{path}{sep}*") # similar paths
matches = [re.search(rf"%s{sep}(\d+)" % path.stem, d) for d in dirs] matches = [re.search(rf"%s{sep}(\d+)" % path.stem, d) for d in dirs]
i = [int(m.groups()[0]) for m in matches if m] # indices i = [int(m.groups()[0]) for m in matches if m] # indices
n = max(i) + 1 if i else 2 # increment number n = max(i) + 1 if i else 2 # increment number
return f"{path}{sep}{n}" # update path return f"{path}{sep}{n}{suffix}" # update path
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论