Update script to hub
Browse files- Boat_dataset.py +39 -20
Boat_dataset.py
CHANGED
@@ -158,28 +158,47 @@ class BoatDataset(datasets.GeneratorBasedBuilder):
|
|
158 |
|
159 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
160 |
def _generate_examples(self, filepath, split):
|
161 |
-
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
162 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
163 |
with open(filepath, encoding="utf-8") as f:
|
164 |
-
for key, row in enumerate(f
|
|
|
|
|
165 |
try:
|
166 |
data = json.loads(row)
|
167 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
except json.JSONDecodeError:
|
169 |
-
print(f"Skipping invalid JSON at line {key}")
|
170 |
continue
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
160 |
def _generate_examples(self, filepath, split):
|
|
|
|
|
161 |
with open(filepath, encoding="utf-8") as f:
|
162 |
+
for key, row in enumerate(f):
|
163 |
+
if not row.strip(): # Skip empty lines
|
164 |
+
continue
|
165 |
try:
|
166 |
data = json.loads(row)
|
167 |
+
# Proceed to use 'data' for generating examples
|
168 |
+
yield key, {
|
169 |
+
"image_id": data["image_id"],
|
170 |
+
"file_name": data["file_name"],
|
171 |
+
"width": data["width"],
|
172 |
+
"height": data["height"],
|
173 |
+
"objects": data["objects"],
|
174 |
+
}
|
175 |
except json.JSONDecodeError:
|
176 |
+
print(f"Skipping invalid JSON at line {key + 1}: {row}")
|
177 |
continue
|
178 |
+
|
179 |
+
# def _generate_examples(self, filepath, split):
|
180 |
+
# # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
181 |
+
# # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
182 |
+
# with open(filepath, encoding="utf-8") as f:
|
183 |
+
# for key, row in enumerate(f, 1): # Start enumeration at 1 for line numbers
|
184 |
+
# try:
|
185 |
+
# data = json.loads(row)
|
186 |
+
# # Your existing processing logic here
|
187 |
+
# except json.JSONDecodeError:
|
188 |
+
# print(f"Skipping invalid JSON at line {key}")
|
189 |
+
# continue
|
190 |
+
# # for key, row in enumerate(f):
|
191 |
+
# # data = json.loads(row)
|
192 |
+
|
193 |
+
# yield key, {
|
194 |
+
# "image_id": data["image_id"],
|
195 |
+
# "file_name": data["file_name"],
|
196 |
+
# "width": data["width"],
|
197 |
+
# "height": data["height"],
|
198 |
+
# "objects": {
|
199 |
+
# "id": data["objects"]["id"],
|
200 |
+
# "area": data["objects"]["area"],
|
201 |
+
# "bbox": data["objects"]["bbox"],
|
202 |
+
# "category": data["objects"]["category"],
|
203 |
+
# },
|
204 |
+
# }
|