From e0f10d7b7f67da5283c6e5283d4723d99a2d932a Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Wed, 19 May 2021 11:43:22 +0300 Subject: [PATCH] Support of context images for 2D tasks (Missed commits) (#3213) * Fixed bug with not filtering file itself in some 3D cases * Added else branch to avoid dublication context images in some cases --- utils/dataset_manifest/utils.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/utils/dataset_manifest/utils.py b/utils/dataset_manifest/utils.py index 09690add..e5987782 100644 --- a/utils/dataset_manifest/utils.py +++ b/utils/dataset_manifest/utils.py @@ -125,20 +125,23 @@ def _detect_related_images_3D(image_paths, root_path): # Update some data applicable for a subset of paths (within the current dirname) latest_dirname = dirname related_images_exist = os.path.isdir(related_images_dirname) - dirname_files = list(filter(lambda x: x != image_path, _list_and_join(dirname))) + dirname_files = list(_list_and_join(dirname)) velodyne_context_images_dirs = [directory for directory in _list_and_join(os.path.normpath(os.path.join(dirname, '..', '..'))) if os.path.isdir(os.path.join(directory, 'data')) and re.search(r'image_\d.*', directory, re.IGNORECASE) ] - if os.path.basename(dirname) == name: + filtered_dirname_files = list(filter(lambda x: x != image_path, dirname_files)) + if len(filtered_dirname_files) and os.path.basename(dirname) == name: # default format (option 2) - related_images[rel_image_path].extend(_prepare_context_list(dirname_files, root_path)) - - filtered_dirname_files = list(filter(lambda x: os.path.splitext(os.path.basename(x))[0] == name, dirname_files)) - if len(filtered_dirname_files): - # default format (option 1) related_images[rel_image_path].extend(_prepare_context_list(filtered_dirname_files, root_path)) + else: + filtered_dirname_files = list( + filter(lambda x: os.path.splitext(os.path.basename(x))[0] == name, filtered_dirname_files) + ) + if len(filtered_dirname_files): + # default format (option 1) + related_images[rel_image_path].extend(_prepare_context_list(filtered_dirname_files, root_path)) if related_images_exist: related_images_dirname = os.path.join(