yunusskeete commited on
Commit
e44992c
·
1 Parent(s): 1d3831b

Upload Carla-COCO-Object-Detection-Dataset.py

Browse files
Carla-COCO-Object-Detection-Dataset.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Permission is hereby granted, free of charge, to any person obtaining
3
+ # a copy of this software and associated documentation files (the
4
+ # "Software"), to deal in the Software without restriction, including
5
+ # without limitation the rights to use, copy, modify, merge, publish,
6
+ # distribute, sublicense, and/or sell copies of the Software, and to
7
+ # permit persons to whom the Software is furnished to do so, subject to
8
+ # the following conditions:
9
+
10
+ # The above copyright notice and this permission notice shall be
11
+ # included in all copies or substantial portions of the Software.
12
+
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ """Carla-COCO-Object-Detection-Dataset"""
21
+
22
+ import collections
23
+ import json
24
+ import os
25
+
26
+ import datasets
27
+
28
+
29
+ logger = datasets.logging.get_logger(__name__)
30
+
31
+ _DESCRIPTION = """\
32
+ This dataset contains 1028 images each 640x380 pixels.
33
+ The dataset is split into 249 test and 779 training examples.
34
+ Every image comes with MS COCO format annotations.
35
+ The dataset was collected in Carla Simulator, driving around in autopilot mode in various environments
36
+ (Town01, Town02, Town03, Town04, Town05) and saving every i-th frame.
37
+ The labels where then automatically generated using the semantic segmentation information.
38
+ """
39
+
40
+ _HOMEPAGE = "https://github.com/yunusskeete/Carla-COCO-Object-Detection-Dataset"
41
+
42
+ _LICENSE = "MIT"
43
+
44
+ _URL = "https://github.com/yunusskeete/Carla-COCO-Object-Detection-Dataset/raw/master/"
45
+ _URLS = {
46
+ "train": _URL + "train.tar.gz",
47
+ "test": _URL + "test.tar.gz",
48
+ }
49
+
50
+ _CATEGORIES = ["automobile", "bike", "motorbike", "traffic_light", "traffic_sign"]
51
+
52
+ class CARLA_COCO(datasets.GeneratorBasedBuilder):
53
+ """Carla-COCO-Object-Detection-Dataset"""
54
+
55
+ VERSION = datasets.Version("1.1.0")
56
+
57
+ def _info(self):
58
+ features = datasets.Features(
59
+ {
60
+ "image_id": datasets.Value("int64"),
61
+ "image": datasets.Image(),
62
+ "width": datasets.Value("int32"),
63
+ "height": datasets.Value("int32"),
64
+ "file_name": datasets.Value("string"),
65
+ "url": datasets.Value("string"),
66
+ "objects": datasets.Sequence(
67
+ {
68
+ "id": datasets.Value("int64"),
69
+ "area": datasets.Value("int64"),
70
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
71
+ "category": datasets.ClassLabel(names=_CATEGORIES),
72
+ }
73
+ ),
74
+ }
75
+ )
76
+ return datasets.DatasetInfo(
77
+ description=_DESCRIPTION,
78
+ features=features,
79
+ homepage=_HOMEPAGE,
80
+ license=_LICENSE,
81
+ )
82
+
83
+ def _split_generators(self, dl_manager):
84
+ downloaded_files = dl_manager.download_and_extract(_URLS)
85
+
86
+ return [
87
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
88
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
89
+ ]
90
+
91
+ def _generate_examples(self, filepath):
92
+ logger.info("generating examples from = %s", filepath)
93
+
94
+ with open(filepath, encoding="utf-8") as f:
95
+ for idx, line in enumerate(f):
96
+ yield idx, json.loads(line)