fix: load script
Browse files
dogs-video-object-tracking-dataset.py
CHANGED
@@ -32,9 +32,9 @@ _LABELS = ["dog"]
|
|
32 |
|
33 |
class DogsVideoObjectTrackingDataset(datasets.GeneratorBasedBuilder):
|
34 |
BUILDER_CONFIGS = [
|
35 |
-
datasets.BuilderConfig(name="video_01", data_dir=f"{_DATA}"),
|
36 |
-
datasets.BuilderConfig(name="video_02", data_dir=f"{_DATA}"),
|
37 |
-
datasets.BuilderConfig(name="video_03", data_dir=f"{_DATA}"),
|
38 |
]
|
39 |
|
40 |
DEFAULT_CONFIG_NAME = "video_01"
|
@@ -79,17 +79,12 @@ class DogsVideoObjectTrackingDataset(datasets.GeneratorBasedBuilder):
|
|
79 |
)
|
80 |
|
81 |
def _split_generators(self, dl_manager):
|
82 |
-
|
83 |
-
f"{self.config.data_dir}{self.config.name}.zip"
|
84 |
-
)
|
85 |
-
annotations = dl_manager.download(f"{_DATA}{self.config.name}.xml")
|
86 |
-
# images = dl_manager.iter_files(images)
|
87 |
return [
|
88 |
datasets.SplitGenerator(
|
89 |
name=datasets.Split.TRAIN,
|
90 |
gen_kwargs={
|
91 |
-
"
|
92 |
-
"annotations": annotations,
|
93 |
},
|
94 |
),
|
95 |
]
|
@@ -103,7 +98,8 @@ class DogsVideoObjectTrackingDataset(datasets.GeneratorBasedBuilder):
|
|
103 |
img.set("id", str(index))
|
104 |
for track in root.iter("track"):
|
105 |
shape = track.find(f".//*[@frame='{index}']")
|
106 |
-
if shape:
|
|
|
107 |
shape.set("label", track.get("label"))
|
108 |
shape.set("track_id", track.get("id"))
|
109 |
img.append(shape)
|
@@ -154,21 +150,22 @@ class DogsVideoObjectTrackingDataset(datasets.GeneratorBasedBuilder):
|
|
154 |
|
155 |
return shape_data
|
156 |
|
157 |
-
def _generate_examples(self,
|
158 |
-
tree = ET.parse(annotations)
|
159 |
root = tree.getroot()
|
160 |
|
161 |
-
for idx, file in enumerate(sorted(os.listdir(f"{
|
162 |
img = self.extract_shapes_from_tracks(root, file, idx)
|
163 |
|
164 |
image_id = img.get("id")
|
165 |
name = img.get("name")
|
166 |
shapes = [self.parse_shape(shape) for shape in img]
|
|
|
167 |
|
168 |
yield idx, {
|
169 |
"id": image_id,
|
170 |
"name": name,
|
171 |
-
"image": f"{
|
172 |
-
"mask": f"{
|
173 |
"shapes": shapes,
|
174 |
}
|
|
|
32 |
|
33 |
class DogsVideoObjectTrackingDataset(datasets.GeneratorBasedBuilder):
|
34 |
BUILDER_CONFIGS = [
|
35 |
+
datasets.BuilderConfig(name="video_01", data_dir=f"{_DATA}video_01.zip"),
|
36 |
+
datasets.BuilderConfig(name="video_02", data_dir=f"{_DATA}video_02.zip"),
|
37 |
+
datasets.BuilderConfig(name="video_03", data_dir=f"{_DATA}video_03.zip"),
|
38 |
]
|
39 |
|
40 |
DEFAULT_CONFIG_NAME = "video_01"
|
|
|
79 |
)
|
80 |
|
81 |
def _split_generators(self, dl_manager):
|
82 |
+
data = dl_manager.download_and_extract(self.config.data_dir)
|
|
|
|
|
|
|
|
|
83 |
return [
|
84 |
datasets.SplitGenerator(
|
85 |
name=datasets.Split.TRAIN,
|
86 |
gen_kwargs={
|
87 |
+
"data": data,
|
|
|
88 |
},
|
89 |
),
|
90 |
]
|
|
|
98 |
img.set("id", str(index))
|
99 |
for track in root.iter("track"):
|
100 |
shape = track.find(f".//*[@frame='{index}']")
|
101 |
+
if not (shape is None):
|
102 |
+
|
103 |
shape.set("label", track.get("label"))
|
104 |
shape.set("track_id", track.get("id"))
|
105 |
img.append(shape)
|
|
|
150 |
|
151 |
return shape_data
|
152 |
|
153 |
+
def _generate_examples(self, data):
|
154 |
+
tree = ET.parse(f"{data}/annotations.xml")
|
155 |
root = tree.getroot()
|
156 |
|
157 |
+
for idx, file in enumerate(sorted(os.listdir(f"{data}/images"))):
|
158 |
img = self.extract_shapes_from_tracks(root, file, idx)
|
159 |
|
160 |
image_id = img.get("id")
|
161 |
name = img.get("name")
|
162 |
shapes = [self.parse_shape(shape) for shape in img]
|
163 |
+
print(shapes)
|
164 |
|
165 |
yield idx, {
|
166 |
"id": image_id,
|
167 |
"name": name,
|
168 |
+
"image": f"{data}/images/{file}",
|
169 |
+
"mask": f"{data}/masks/{file}",
|
170 |
"shapes": shapes,
|
171 |
}
|