• Glenn Jocher's avatar
    Fix `increment_path()` explicit file vs dir handling (#5523) · 85350533
    Glenn Jocher 提交于
    Resolves https://github.com/ultralytics/yolov5/pull/5341#issuecomment-961774729
    
    Tests:
    ```python
    import glob
    import re
    from pathlib import Path
    
    
    def increment_path(path, exist_ok=False, sep='', mkdir=False):
        # Increment file or directory path, i.e. runs/exp --> runs/exp{sep}2, runs/exp{sep}3, ... etc.
        path = Path(path)  # os-agnostic
        if path.exists() and not exist_ok:
            path, suffix = (path.with_suffix(''), path.suffix) if path.is_file() else (path, '')
            dirs = glob.glob(f"{path}{sep}*")  # similar paths
            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
            n = max(i) + 1 if i else 2  # increment number
            path = Path(f"{path}{sep}{n}{suffix}")  # increment path
        if mkdir:
            path.mkdir(parents=True, exist_ok=True)  # make directory
        return path
    
    
    print(increment_path('runs'))
    print(increment_path('export.py'))
    print(increment_path('abc.def.dir'))
    print(increment_path('abc.def.file'))
    ```
    85350533
名称
最后提交
最后更新
..
aws 正在载入提交数据...
flask_rest_api 正在载入提交数据...
google_app_engine 正在载入提交数据...
loggers 正在载入提交数据...
__init__.py 正在载入提交数据...
activations.py 正在载入提交数据...
augmentations.py 正在载入提交数据...
autoanchor.py 正在载入提交数据...
autobatch.py 正在载入提交数据...
callbacks.py 正在载入提交数据...
datasets.py 正在载入提交数据...
downloads.py 正在载入提交数据...
general.py 正在载入提交数据...
loss.py 正在载入提交数据...
metrics.py 正在载入提交数据...
plots.py 正在载入提交数据...
torch_utils.py 正在载入提交数据...