unearthed_artifacts / unearthedartifacts.py
Unearthed's picture
Upload unearthedartifacts.py with huggingface_hub
647636c verified
Raw History Blame Contribute Delete
1.41 kB
import tensorflow_datasets as tfds
class UnearthedArtifacts(tfds.core.GeneratorBasedBuilder):
VERSION = tfds.core.Version("1.0.0")
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description="Artifact image dataset.",
features=tfds.features.FeaturesDict({
"image": tfds.features.Image(),
"label": tfds.features.ClassLabel(
names=["scrapers", "arrowheads", "axehammerstones"]
),
}),
supervised_keys=("image", "label"),
)
def _split_generators(self, dl_manager):
img_dir = r"C:\Users\chava\unearthed_artifacts_dataset"
return {
"train": self._generate_examples(img_dir),
}
def _generate_examples(self, img_dir):
import os
classes = ["scrapers", "arrowheads", "axehammerstones"]
for label in classes:
class_path = os.path.join(img_dir, label)
if not os.path.exists(class_path):
continue
for img_name in os.listdir(class_path):
if img_name.lower().endswith((".jpg", ".jpeg", ".png")):
yield f"{label}_{img_name}", {
"image": os.path.join(class_path, img_name),
"label": label,
}