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
This commit is contained in:
Jiacong Fang authored and GitHub committed 2020-10-05 15:46:32 +02:00
1 parent 35fe98543c
commit c5d2331897
1 file changed
+1 -1
+1 -1
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 '')