From c0af845f96b9e580c83c4916b816dc07aa5752c0 Mon Sep 17 00:00:00 2001 From: "Stephen A. Balaban" Date: Sat, 24 Aug 2013 14:28:20 -0700 Subject: [PATCH 1/2] Fixed indentation, added enumerate. The if statement looked like it needed to be indented inside of the for loop. Moved from range(len(list)) item = list[index] -> index, item in enumerate(list). It's more pythonic. --- python/helpers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/helpers.py b/python/helpers.py index e75896f..7a0bf7e 100644 --- a/python/helpers.py +++ b/python/helpers.py @@ -27,7 +27,7 @@ def ReadAllImages(char_dir, bg_dir, char_classes, labels=np.zeros(0) k = 0 max_allocate=1e5 - for class_index in range(len(char_classes)): + for class_index, cur_class in enumerate(char_classes): cur_class = char_classes[class_index] if cur_class == '_': imgs_dir = bg_dir # background class @@ -40,14 +40,14 @@ def ReadAllImages(char_dir, bg_dir, char_classes, for root, dirs, files in os.walk(imgs_dir): add_files = [os.path.join(root, f) for f in files] filelist += add_files - if cur_class == '_': - if (max_bg < np.inf) and (len(files) > max_bg): - random.shuffle(filelist) - filelist = filelist[0:max_bg] - else: - if (max_per_class < np.inf) and (len(filelist) > max_per_class): - random.shuffle(filelist) - filelist = filelist[0:max_per_class] + if cur_class == '_': + if (max_bg < np.inf) and (len(files) > max_bg): + random.shuffle(filelist) + filelist = filelist[0:max_bg] + else: + if (max_per_class < np.inf) and (len(filelist) > max_per_class): + random.shuffle(filelist) + filelist = filelist[0:max_per_class] for path in filelist: p1,ext=os.path.splitext(path) From a60745c5dcef784c8f7f9854b2e183e4b7bb26f1 Mon Sep 17 00:00:00 2001 From: "Stephen A. Balaban" Date: Sat, 24 Aug 2013 14:57:02 -0700 Subject: [PATCH 2/2] Forgot to remove cur_class = char_classes[class_index]. --- python/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/helpers.py b/python/helpers.py index 7a0bf7e..044e2df 100644 --- a/python/helpers.py +++ b/python/helpers.py @@ -28,7 +28,6 @@ def ReadAllImages(char_dir, bg_dir, char_classes, k = 0 max_allocate=1e5 for class_index, cur_class in enumerate(char_classes): - cur_class = char_classes[class_index] if cur_class == '_': imgs_dir = bg_dir # background class else: