Stanislav Kalinin commited on
Commit
b946dca
1 Parent(s): 1c4dfa3

feat: Add splits to train val test

Browse files
Files changed (2) hide show
  1. dataset_infos.json +1 -1
  2. school_notebooks_EN.py +37 -10
dataset_infos.json CHANGED
@@ -1 +1 @@
1
- {"default": {"description": "", "citation": "", "homepage": "", "license": "", "features": {"image": {"decode": true, "id": null, "_type": "Image"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "school_notebooks_en", "config_name": "default", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 15374, "num_examples": 90, "dataset_name": "school_notebooks_en"}}, "download_checksums": {"images.zip": {"num_bytes": 356400252, "checksum": "295ab37246a1ec976f50019ab77b3bb35543b0cdcbd2b825a7949c4959448a75"}}, "download_size": 356400252, "post_processing_size": null, "dataset_size": 15374, "size_in_bytes": 356415626}}
 
1
+ {"default": {"description": "", "citation": "", "homepage": "", "license": "", "features": {"image": {"decode": true, "id": null, "_type": "Image"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "school_notebooks_en", "config_name": "default", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 11957, "num_examples": 70, "dataset_name": "school_notebooks_en"}, "test": {"name": "test", "num_bytes": 1692, "num_examples": 10, "dataset_name": "school_notebooks_en"}, "validation": {"name": "validation", "num_bytes": 1726, "num_examples": 10, "dataset_name": "school_notebooks_en"}}, "download_checksums": {"images.zip": {"num_bytes": 356400252, "checksum": "295ab37246a1ec976f50019ab77b3bb35543b0cdcbd2b825a7949c4959448a75"}, "annotations_train.json": {"num_bytes": 8644229, "checksum": "2b52b1876e47c6970e2ba97f57fe2a431a2bca0c5b9450360c4bf481643c0b5f"}, "annotations_test.json": {"num_bytes": 687288, "checksum": "c241e966d26d10cd7fa19730489cac104ebebfd9931d0acd0c4fb7369a958672"}, "annotations_val.json": {"num_bytes": 1768738, "checksum": "8a6b80a2c73ca25a2b2b23d4620c4c34492b728ed094a824e82f49427712c271"}}, "download_size": 367500507, "post_processing_size": null, "dataset_size": 15375, "size_in_bytes": 367515882}}
school_notebooks_EN.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import datasets
3
 
4
 
@@ -13,24 +14,50 @@ class SchoolNotebooks(datasets.GeneratorBasedBuilder):
13
  )
14
 
15
  def _split_generators(self, dl_manager):
16
- DL_URLS = [
17
- "images.zip"
18
- ]
19
- data_files = dl_manager.download_and_extract(DL_URLS)
 
 
 
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
- example = {
34
- "image": image_path,
35
- }
36
- yield idx, example
 
 
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