@@ -52,17 +52,6 @@ def _polygons_to_masks(
52
52
)
53
53
54
54
55
- def _pair_image_with_annotation (
56
- image_paths : List [Union [str , Path ]], annotation_paths : List [Union [str , Path ]]
57
- ) -> List [Tuple [Union [str , Path ], Union [str , Path ]]]:
58
- image_dict = {p .stem : p for p in image_paths }
59
- return [
60
- (image_dict [annotation_path .stem ], annotation_path )
61
- for annotation_path in annotation_paths
62
- if annotation_path .stem in image_dict
63
- ]
64
-
65
-
66
55
def _with_mask (lines : List [str ]) -> bool :
67
56
return any ([len (line .split ()) > 5 for line in lines ])
68
57
@@ -137,14 +126,21 @@ def load_yolo_annotations(
137
126
annotation_paths = list_files_with_extensions (
138
127
directory = annotations_directory_path , extensions = ["txt" ]
139
128
)
140
- path_pairs = _pair_image_with_annotation (
141
- image_paths = image_paths , annotation_paths = annotation_paths
142
- )
129
+
143
130
classes = _extract_class_names (file_path = data_yaml_path )
144
131
images = {}
145
132
annotations = {}
146
- for image_path , annotation_path in path_pairs :
133
+
134
+ for image_path in image_paths :
135
+ image_name = Path (image_path ).stem
147
136
image = cv2 .imread (str (image_path ))
137
+
138
+ annotation_path = os .path .join (annotations_directory_path , f"{ image_name } .txt" )
139
+ if not os .path .exists (annotation_path ):
140
+ images [image_path .name ] = image
141
+ annotations [image_path .name ] = Detections .empty ()
142
+ continue
143
+
148
144
lines = read_txt_file (str (annotation_path ))
149
145
h , w , _ = image .shape
150
146
resolution_wh = (w , h )
0 commit comments