1aurent commited on
Commit
07ddcfe
1 Parent(s): 9891c69

Create gen_script.py

Browse files
Files changed (1) hide show
  1. gen_script.py +93 -0
gen_script.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from functools import cached_property
2
+ from pathlib import Path
3
+
4
+ import datasets
5
+
6
+ _VERSION = "0.1.0"
7
+
8
+ _CITATION = """
9
+ @inproceedings{5539970,
10
+ title = {SUN database: Large-scale scene recognition from abbey to zoo},
11
+ author = {Xiao, Jianxiong and Hays, James and Ehinger, Krista A. and Oliva, Aude and Torralba, Antonio},
12
+ year = 2010,
13
+ booktitle = {2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition},
14
+ volume = {},
15
+ number = {},
16
+ pages = {3485--3492},
17
+ doi = {10.1109/CVPR.2010.5539970},
18
+ keywords = {Sun;Large-scale systems;Layout;Humans;Image databases;Computer vision;Anthropometry;Bridges;Legged locomotion;Spatial databases}
19
+ }
20
+ @article{Xiao2014SUNDE,
21
+ title = {SUN Database: Exploring a Large Collection of Scene Categories},
22
+ author = {Jianxiong Xiao and Krista A. Ehinger and James Hays and Antonio Torralba and Aude Oliva},
23
+ year = 2014,
24
+ journal = {International Journal of Computer Vision},
25
+ volume = 119,
26
+ pages = {3--22},
27
+ url = {https://api.semanticscholar.org/CorpusID:10224573}
28
+ }
29
+ """
30
+
31
+ _DESCRIPTION = """
32
+ Scene categorization is a fundamental problem in computer vision.
33
+ However, scene understanding research has been constrained by the limited scope of currently-used databases which do not capture the full variety of scene categories.
34
+ Whereas standard databases for object categorization contain hundreds of different classes of objects, the largest available dataset of scene categories contains only 15 classes.
35
+ In this paper we propose the extensive Scene UNderstanding (SUN) database that contains 899 categories and 130,519 images.
36
+ We use 397 well-sampled categories to evaluate numerous state-of-the-art algorithms for scene recognition and establish new bounds of performance.
37
+ We measure human scene classification performance on the SUN database and compare this with computational methods.
38
+ """
39
+
40
+ _HOMEPAGE = "https://vision.princeton.edu/projects/2010/SUN/"
41
+
42
+ _LICENSE = ""
43
+
44
+ _URL = "http://vision.princeton.edu/projects/2010/SUN/SUN397.tar.gz"
45
+
46
+
47
+ class SUN397(datasets.GeneratorBasedBuilder):
48
+ DEFAULT_WRITER_BATCH_SIZE = 1000
49
+
50
+ @cached_property
51
+ def archive_path(self):
52
+ dl_manager = datasets.DownloadManager()
53
+ return Path(dl_manager.download_and_extract(_URL)) / "SUN397"
54
+
55
+ @property
56
+ def features(self):
57
+ return datasets.Features(
58
+ {
59
+ "image": datasets.Image(mode="RGB"),
60
+ "label": datasets.ClassLabel(names_file=self.archive_path / "ClassName.txt"),
61
+ }
62
+ )
63
+
64
+ def _info(self):
65
+ return datasets.DatasetInfo(
66
+ features=self.features,
67
+ supervised_keys=None,
68
+ description=_DESCRIPTION,
69
+ homepage=_HOMEPAGE,
70
+ license=_LICENSE,
71
+ version=_VERSION,
72
+ citation=_CITATION,
73
+ )
74
+
75
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
76
+ images = sorted(list(self.archive_path.rglob("*.jpg")))
77
+
78
+ return [
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.TRAIN,
81
+ gen_kwargs={"images": images},
82
+ ),
83
+ ]
84
+
85
+ def _generate_examples(self, images: list[Path]):
86
+ for i, image in enumerate(images):
87
+ yield (
88
+ i,
89
+ {
90
+ "image": str(image),
91
+ "label": f"/{image.relative_to(self.archive_path).parent}",
92
+ },
93
+ )