Skip to content

Commit e6d03b8

Browse files
committed
defer image info requesting in yolo
1 parent cfc56d1 commit e6d03b8

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

datumaro/datumaro/components/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def load_project_as_dataset(url):
142142

143143
class Environment:
144144
_builtin_plugins = None
145-
PROJECT_EXTRACTOR_NAME = 'project'
145+
PROJECT_EXTRACTOR_NAME = 'datumaro_project'
146146

147147
def __init__(self, config=None):
148148
config = Config(config,

datumaro/datumaro/plugins/yolo_format/extractor.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ def __init__(self, config_path, image_info=None):
9393
(osp.splitext(osp.basename(p.strip()))[0], p.strip())
9494
for p in f
9595
)
96-
97-
for item_id, image_path in subset.items.items():
98-
image_path = self._make_local_path(image_path)
99-
if not osp.isfile(image_path) and item_id not in image_info:
100-
raise Exception("Can't find image '%s'" % item_id)
101-
10296
subsets[subset_name] = subset
10397

10498
self._subsets = subsets
@@ -122,10 +116,9 @@ def _get(self, item_id, subset_name):
122116
image_path = self._make_local_path(item)
123117
image_size = self._image_info.get(item_id)
124118
image = Image(path=image_path, size=image_size)
125-
h, w = image.size
126119

127120
anno_path = osp.splitext(image_path)[0] + '.txt'
128-
annotations = self._parse_annotations(anno_path, w, h)
121+
annotations = self._parse_annotations(anno_path, image)
129122

130123
item = DatasetItem(id=item_id, subset=subset_name,
131124
image=image, annotations=annotations)
@@ -134,21 +127,30 @@ def _get(self, item_id, subset_name):
134127
return item
135128

136129
@staticmethod
137-
def _parse_annotations(anno_path, image_width, image_height):
130+
def _parse_annotations(anno_path, image):
131+
lines = []
138132
with open(anno_path, 'r') as f:
139-
annotations = []
140133
for line in f:
141-
label_id, xc, yc, w, h = line.strip().split()
142-
label_id = int(label_id)
143-
w = float(w)
144-
h = float(h)
145-
x = float(xc) - w * 0.5
146-
y = float(yc) - h * 0.5
147-
annotations.append(Bbox(
148-
round(x * image_width, 1), round(y * image_height, 1),
149-
round(w * image_width, 1), round(h * image_height, 1),
150-
label=label_id
151-
))
134+
line = line.strip()
135+
if line:
136+
lines.append(line)
137+
138+
annotations = []
139+
if lines:
140+
image_height, image_width = image.size # use image info late
141+
for line in lines:
142+
label_id, xc, yc, w, h = line.split()
143+
label_id = int(label_id)
144+
w = float(w)
145+
h = float(h)
146+
x = float(xc) - w * 0.5
147+
y = float(yc) - h * 0.5
148+
annotations.append(Bbox(
149+
round(x * image_width, 1), round(y * image_height, 1),
150+
round(w * image_width, 1), round(h * image_height, 1),
151+
label=label_id
152+
))
153+
152154
return annotations
153155

154156
@staticmethod

0 commit comments

Comments
 (0)