Upload modelnet10.py
Browse files- modelnet10.py +81 -0
modelnet10.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hugging Face `datasets` loading script for the local ModelNet10 layout (CSV + ModelNet10/*.off)."""
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from datasets import (
|
| 7 |
+
BuilderConfig,
|
| 8 |
+
DatasetInfo,
|
| 9 |
+
Features,
|
| 10 |
+
GeneratorBasedBuilder,
|
| 11 |
+
Split,
|
| 12 |
+
SplitGenerator,
|
| 13 |
+
Value,
|
| 14 |
+
Version,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ModelNet10(GeneratorBasedBuilder):
|
| 19 |
+
"""Build train/test splits from metadata_modelnet10.csv next to the ModelNet10 mesh folder."""
|
| 20 |
+
|
| 21 |
+
VERSION = Version("1.0.0")
|
| 22 |
+
BUILDER_CONFIGS = [BuilderConfig(name="default", version=VERSION)]
|
| 23 |
+
DEFAULT_CONFIG_NAME = "default"
|
| 24 |
+
|
| 25 |
+
def _info(self):
|
| 26 |
+
return DatasetInfo(
|
| 27 |
+
description=(
|
| 28 |
+
"ModelNet10: 3D mesh classification subset (10 categories). "
|
| 29 |
+
"Each row references an OFF file under ModelNet10/ and metadata_modelnet10.csv at the dataset root."
|
| 30 |
+
),
|
| 31 |
+
features=Features(
|
| 32 |
+
{
|
| 33 |
+
"object_id": Value("string"),
|
| 34 |
+
"class": Value("string"),
|
| 35 |
+
"split": Value("string"),
|
| 36 |
+
"file_path": Value("string"),
|
| 37 |
+
}
|
| 38 |
+
),
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
def _split_generators(self, dl_manager):
|
| 42 |
+
if self.config.data_dir is not None:
|
| 43 |
+
data_dir = os.path.abspath(os.path.expanduser(self.config.data_dir))
|
| 44 |
+
if not os.path.isdir(data_dir):
|
| 45 |
+
raise FileNotFoundError(f"data_dir is not a directory: {data_dir}")
|
| 46 |
+
elif self.config.data_files is not None:
|
| 47 |
+
data_dir = dl_manager.download_and_extract(self.config.data_files)
|
| 48 |
+
else:
|
| 49 |
+
raise ValueError(
|
| 50 |
+
"Pass data_dir=... (folder containing metadata_modelnet10.csv and ModelNet10/) "
|
| 51 |
+
"or data_files=... when calling load_dataset."
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
return [
|
| 55 |
+
SplitGenerator(
|
| 56 |
+
name=Split.TRAIN,
|
| 57 |
+
gen_kwargs={"split": "train", "data_dir": data_dir},
|
| 58 |
+
),
|
| 59 |
+
SplitGenerator(
|
| 60 |
+
name=Split.TEST,
|
| 61 |
+
gen_kwargs={"split": "test", "data_dir": data_dir},
|
| 62 |
+
),
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
def _generate_examples(self, split, data_dir):
|
| 66 |
+
csv_path = os.path.join(data_dir, "metadata_modelnet10.csv")
|
| 67 |
+
if not os.path.isfile(csv_path):
|
| 68 |
+
raise FileNotFoundError(f"Missing metadata CSV: {csv_path}")
|
| 69 |
+
|
| 70 |
+
with open(csv_path, newline="", encoding="utf-8") as f:
|
| 71 |
+
reader = csv.DictReader(f)
|
| 72 |
+
for row in reader:
|
| 73 |
+
if row["split"] != split:
|
| 74 |
+
continue
|
| 75 |
+
object_id = row["object_id"]
|
| 76 |
+
yield object_id, {
|
| 77 |
+
"object_id": object_id,
|
| 78 |
+
"class": row["class"],
|
| 79 |
+
"split": row["split"],
|
| 80 |
+
"file_path": os.path.join(data_dir, "ModelNet10", row["object_path"]),
|
| 81 |
+
}
|