Testing image dataset upload
Browse files- faceid-data2.py +72 -0
faceid-data2.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset_script.py
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
from datasets import (
|
| 8 |
+
GeneratorBasedBuilder,
|
| 9 |
+
DatasetInfo,
|
| 10 |
+
SplitGenerator,
|
| 11 |
+
Features,
|
| 12 |
+
Sequence,
|
| 13 |
+
Value,
|
| 14 |
+
Image
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
_CITATION = """\
|
| 18 |
+
@misc{faceid2025,
|
| 19 |
+
title={FaceID for nanoVLM},
|
| 20 |
+
author={Your Name},
|
| 21 |
+
year={2025},
|
| 22 |
+
}
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
_DESCRIPTION = """
|
| 26 |
+
FaceID dataset: for each image, a single-question Q&A pair:
|
| 27 |
+
"Question: Who is the person?" → "Answer: <Name>"
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
class FaceIDDataset(GeneratorBasedBuilder):
|
| 31 |
+
|
| 32 |
+
VERSION = datasets.Version("1.0.0")
|
| 33 |
+
|
| 34 |
+
def _info(self):
|
| 35 |
+
return DatasetInfo(
|
| 36 |
+
description=_DESCRIPTION,
|
| 37 |
+
features=Features({
|
| 38 |
+
# a *list* of images (we only have one per example, but must match your JSONL)
|
| 39 |
+
"images": Sequence(feature=Image(decode=True)),
|
| 40 |
+
# a list of QA dicts
|
| 41 |
+
"texts": Sequence({
|
| 42 |
+
"user": Value("string"),
|
| 43 |
+
"assistant": Value("string"),
|
| 44 |
+
"source": Value("string"),
|
| 45 |
+
}),
|
| 46 |
+
}),
|
| 47 |
+
supervised_keys=None,
|
| 48 |
+
homepage="https://huggingface.co/datasets/your-username/faceid-data2",
|
| 49 |
+
citation=_CITATION,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
def _split_generators(self, dl_manager):
|
| 53 |
+
# we already have JSONL + images in the same folder, no download needed
|
| 54 |
+
data_dir = Path(__file__).parent
|
| 55 |
+
return [
|
| 56 |
+
SplitGenerator(name=datasets.Split.TRAIN,
|
| 57 |
+
gen_kwargs={"jsonl": data_dir / "train.jsonl"}),
|
| 58 |
+
SplitGenerator(name=datasets.Split.VALIDATION,
|
| 59 |
+
gen_kwargs={"jsonl": data_dir / "val.jsonl"}),
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
def _generate_examples(self, jsonl):
|
| 63 |
+
base = Path(__file__).parent
|
| 64 |
+
with open(jsonl, "r", encoding="utf-8") as f:
|
| 65 |
+
for idx, line in enumerate(f):
|
| 66 |
+
ex = json.loads(line)
|
| 67 |
+
# images is a list of relative paths under this repo
|
| 68 |
+
img_list = [ str(base / p) for p in ex["images"] ]
|
| 69 |
+
yield idx, {
|
| 70 |
+
"images": img_list,
|
| 71 |
+
"texts": ex["texts"]
|
| 72 |
+
}
|