|
"""TODO: Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
from safetensors import safe_open |
|
import pandas as pd |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {A great new dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2022} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve this great NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
"image_ids": "https://huggingface.co/datasets/JLD/unsplash25k-image-embeddings/blob/main/data/image_ids.feather.zstd", |
|
"embeddings": "https://huggingface.co/datasets/JLD/unsplash25k-image-embeddings/blob/main/data/unsplash_embeddings.safetensors" |
|
} |
|
|
|
class Unsplash25kImageEmbeddingsDataset(datasets.GeneratorBasedBuilder): |
|
"""_summary_ |
|
|
|
Args: |
|
datasets (_type_): _description_ |
|
""" |
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"image_id": datasets.Value("string"), |
|
"image_embedding": datasets.Features({'x': datasets.Array2D(shape=(1, 512), dtype='float16')}) |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
embeddings_path = dl_manager.download(_URLS["embeddings"]) |
|
image_ids_path = dl_manager.download(_URLS["image_ids"]) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.ALL, |
|
gen_kwargs={ |
|
"embeddings_path": embeddings_path, |
|
"image_ids": image_ids_path |
|
} |
|
) |
|
] |
|
|
|
def _generate_examples(self, embeddings_path, image_ids_path): |
|
tensors = {} |
|
image_ids = pd.read_feather(image_ids_path, compression="zstd") |
|
with safe_open(embeddings_path, framework="pt", device="cpu") as f: |
|
for key in f.keys(): |
|
tensors[key] = f.get_tensor(key) |
|
for num_id, image_id in enumerate(image_ids): |
|
yield {"image_id": image_id, "image_embedding": tensors["embeddings"][num_id]} |
|
|
|
|