From c5d233189729a9e7e25d3aa2d347aed02b545d30 Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Mon, 5 Oct 2020 21:46:32 +0800 Subject: [PATCH] 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 --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index b3253b1..86c5842 100755 --- a/utils/general.py +++ b/utils/general.py @@ -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 '')