Stanislav Kalinin
commited on
Commit
•
a4796ec
1
Parent(s):
c5a2483
feat: Add splits to train val test
Browse files
Peter.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import datasets
|
3 |
|
4 |
|
@@ -13,24 +14,50 @@ class Peter(datasets.GeneratorBasedBuilder):
|
|
13 |
)
|
14 |
|
15 |
def _split_generators(self, dl_manager):
|
16 |
-
|
17 |
-
"images.zip"
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
return [
|
22 |
datasets.SplitGenerator(
|
23 |
name=datasets.Split.TRAIN,
|
24 |
gen_kwargs={
|
25 |
-
"image_paths": dl_manager.iter_files(data_files),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
},
|
27 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
]
|
29 |
|
30 |
-
def _generate_examples(self, image_paths):
|
31 |
"""Generate examples."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
for idx, image_path in enumerate(image_paths):
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
1 |
import os
|
2 |
+
import json
|
3 |
import datasets
|
4 |
|
5 |
|
|
|
14 |
)
|
15 |
|
16 |
def _split_generators(self, dl_manager):
|
17 |
+
_URLS = {
|
18 |
+
"images": "images.zip",
|
19 |
+
"train_data": "annotations_train.json",
|
20 |
+
"test_data": "annotations_test.json",
|
21 |
+
"val_data": "annotations_val.json"
|
22 |
+
}
|
23 |
+
data_files = dl_manager.download_and_extract(_URLS)
|
24 |
|
25 |
return [
|
26 |
datasets.SplitGenerator(
|
27 |
name=datasets.Split.TRAIN,
|
28 |
gen_kwargs={
|
29 |
+
"image_paths": dl_manager.iter_files(data_files["images"]),
|
30 |
+
"annotation_path": data_files["train_data"],
|
31 |
+
},
|
32 |
+
),
|
33 |
+
datasets.SplitGenerator(
|
34 |
+
name=datasets.Split.TEST,
|
35 |
+
gen_kwargs={
|
36 |
+
"image_paths": dl_manager.iter_files(data_files["images"]),
|
37 |
+
"annotation_path": data_files["test_data"],
|
38 |
},
|
39 |
),
|
40 |
+
datasets.SplitGenerator(
|
41 |
+
name=datasets.Split.VALIDATION,
|
42 |
+
gen_kwargs={
|
43 |
+
"image_paths": dl_manager.iter_files(data_files["images"]),
|
44 |
+
"annotation_path": data_files["val_data"],
|
45 |
+
},
|
46 |
+
)
|
47 |
]
|
48 |
|
49 |
+
def _generate_examples(self, image_paths, annotation_path):
|
50 |
"""Generate examples."""
|
51 |
+
with open(annotation_path, 'r') as f:
|
52 |
+
data = json.load(f)
|
53 |
+
|
54 |
+
image_names = set()
|
55 |
+
for image_data in data['images']:
|
56 |
+
image_names.add(image_data['file_name'])
|
57 |
+
|
58 |
for idx, image_path in enumerate(image_paths):
|
59 |
+
if os.path.basename(image_path) in image_names:
|
60 |
+
example = {
|
61 |
+
"image": image_path,
|
62 |
+
}
|
63 |
+
yield idx, example
|