Create datasets_infos.json
Browse files- datasets_infos.json +55 -0
datasets_infos.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
# Baca metadata dari file JSON
|
| 5 |
+
with open("notes.json", "r") as json_file:
|
| 6 |
+
metadata = json.load(json_file)
|
| 7 |
+
|
| 8 |
+
# Konfigurasi dataset
|
| 9 |
+
class CustomDatasetConfig(datasets.BuilderConfig):
|
| 10 |
+
def __init__(self, metadata, **kwargs):
|
| 11 |
+
super(CustomDatasetConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 12 |
+
self.metadata = metadata
|
| 13 |
+
|
| 14 |
+
# Kelas untuk membangun dataset
|
| 15 |
+
class CustomDataset(datasets.GeneratorBasedBuilder):
|
| 16 |
+
VERSION = datasets.Version("1.0.0")
|
| 17 |
+
BUILDER_CONFIGS = [
|
| 18 |
+
CustomDatasetConfig(metadata=metadata),
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
def _info(self):
|
| 22 |
+
features = datasets.Features(
|
| 23 |
+
{
|
| 24 |
+
"image_id": datasets.Value("int64"),
|
| 25 |
+
"image": datasets.Image(),
|
| 26 |
+
"label": datasets.ClassLabel(names=self.config.metadata["classes"]),
|
| 27 |
+
}
|
| 28 |
+
)
|
| 29 |
+
return datasets.DatasetInfo(
|
| 30 |
+
features=features,
|
| 31 |
+
description=self.config.metadata["description"],
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
def _split_generators(self, dl_manager):
|
| 35 |
+
return [
|
| 36 |
+
datasets.SplitGenerator(
|
| 37 |
+
name=datasets.Split.TRAIN,
|
| 38 |
+
gen_kwargs={
|
| 39 |
+
"data": self.config.metadata["data"],
|
| 40 |
+
},
|
| 41 |
+
),
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
def _generate_examples(self, data):
|
| 45 |
+
for item in data:
|
| 46 |
+
yield item["image_id"], {
|
| 47 |
+
"image_id": item["image_id"],
|
| 48 |
+
"image": {"path": item["image_path"]},
|
| 49 |
+
"label": item["label"],
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# Usage example
|
| 53 |
+
builder = CustomDataset()
|
| 54 |
+
info = builder.info
|
| 55 |
+
dataset = builder.as_dataset()
|