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

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

Browse files
Carla-COCO-Object-Detection-Dataset.py CHANGED
@@ -55,6 +55,8 @@ class CARLA_COCO(datasets.GeneratorBasedBuilder):
55
  VERSION = datasets.Version("1.1.0")
56
 
57
  def _info(self):
 
 
58
  features = datasets.Features(
59
  {
60
  "image_id": datasets.Value("int64"),
@@ -81,16 +83,38 @@ class CARLA_COCO(datasets.GeneratorBasedBuilder):
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)
 
55
  VERSION = datasets.Version("1.1.0")
56
 
57
  def _info(self):
58
+ """This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset"""
59
+
60
  features = datasets.Features(
61
  {
62
  "image_id": datasets.Value("int64"),
 
83
  )
84
 
85
  def _split_generators(self, dl_manager):
86
+ """This method is tasked with downloading/extracting the data and defining the splits depending on the configuration"""
87
+
88
  downloaded_files = dl_manager.download_and_extract(_URLS)
89
 
90
  return [
91
+ datasets.SplitGenerator(
92
+ name=datasets.Split.TRAIN,
93
+ # These kwargs will be passed to _generate_examples
94
+ gen_kwargs={
95
+ "filepath": os.path.join(downloaded_files["train"], "train.jsonl"),
96
+ "split": "train"
97
+ }
98
+ ),
99
+ datasets.SplitGenerator(
100
+ name=datasets.Split.TEST,
101
+ # These kwargs will be passed to _generate_examples
102
+ gen_kwargs={
103
+ "filepath": os.path.join(downloaded_files["test"], "test.jsonl"),
104
+ "split": "test"
105
+ }
106
+ ),
107
  ]
108
 
109
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
110
  def _generate_examples(self, filepath):
111
+ """
112
+ This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
113
+ The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
114
+ """
115
+
116
  logger.info("generating examples from = %s", filepath)
117
 
118
  with open(filepath, encoding="utf-8") as f:
119
+ for key, row in enumerate(f):
120
+ yield key, json.loads(row)