Fix increment_dir to use run_xxx for logdir (#1058)

* Fix increment_dir to use run_xxx for logdir 

Rerunning train.py with logdir in the form of `run_xxx` causes index slicing in
```
n = max([int(x[len(dir):x.find('_') if '_' in Path(x).name else None]) for x in d]) + 1  # increment
```
to underflow.

* Replace find with rfind
pull/1086/head
Jiacong Fang 2020-10-05 21:46:32 +08:00 committed by GitHub
parent 35fe98543c
commit c5d2331897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -948,7 +948,7 @@ def increment_dir(dir, comment=''):
dir = str(Path(dir)) # os-agnostic
d = sorted(glob.glob(dir + '*')) # directories
if len(d):
n = max([int(x[len(dir):x.find('_') if '_' in x else None]) for x in d]) + 1 # increment
n = max([int(x[len(dir):x.rfind('_') if '_' in Path(x).name else None]) for x in d]) + 1 # increment
return dir + str(n) + ('_' + comment if comment else '')