JAWCF commited on
Commit
c0ebcdd
·
1 Parent(s): 27e30d5

Create objects.py

Browse files
Files changed (1) hide show
  1. objects.py +75 -0
objects.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.Wikipedia
15
+
16
+ # Lint as: python3
17
+ """Dream!n character datasets"""
18
+
19
+ import datasets
20
+ import json
21
+
22
+ _CITATION = """
23
+ """
24
+
25
+ _DESCRIPTION = "Dream!n object datasets"
26
+
27
+
28
+ _DATASET_URL = "https://huggingface.co/datasets/JAWCF/objects/resolve/main/images.tar.gz"
29
+
30
+ json_url = urlopen("https://huggingface.co/datasets/JAWCF/objects/resolve/main/objects.json")
31
+ DICT_DESC = json.loads(json_url.read())
32
+
33
+ class Characters(datasets.GeneratorBasedBuilder):
34
+
35
+ def _info(self):
36
+ features = datasets.Features({
37
+ 'image': datasets.Image(),
38
+ 'text': datasets.Value('string')
39
+ })
40
+ return datasets.DatasetInfo(
41
+ # This is the description that will appear on the datasets page.
42
+ description=_DESCRIPTION,
43
+ # This defines the different columns of the dataset and their types
44
+ features=features, # Here we define them above because they are different between the two configurations
45
+ supervised_keys=None,
46
+ # Homepage of the dataset for documentation
47
+ homepage="",
48
+ # License for the dataset if available
49
+ license="",
50
+ # Citation for the dataset
51
+ citation=_CITATION,
52
+ )
53
+
54
+ def _split_generators(self, dl_manager):
55
+ path = dl_manager.download(_DATASET_URL)
56
+ image_iters = dl_manager.iter_archive(path)
57
+ splits = [
58
+ datasets.SplitGenerator(
59
+ name=datasets.Split.TRAIN,
60
+ gen_kwargs={
61
+ "images": image_iters
62
+ }
63
+ ),
64
+ ]
65
+ return splits
66
+
67
+ def _generate_examples(self, images):
68
+ """Yields examples."""
69
+ idx = 0
70
+ for filepath, image in images:
71
+ yield idx, {
72
+ "image": {"path": filepath, "bytes": image.read()},
73
+ "text" : DICT_DESC[filepath],
74
+ }
75
+ idx+=1