|
import os |
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This dataset includes images with associated IDs, titles, and URLs. There are two types of images: 'Listing Image' and 'Search-image'. |
|
""" |
|
_LABEL_MAP = { |
|
'Listing Image': 'listing_image', |
|
'Search-image': 'search_image', |
|
} |
|
|
|
class MyDatasetConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for MyDataset.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for MyDataset. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(MyDatasetConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs) |
|
|
|
|
|
class MyDataset(datasets.GeneratorBasedBuilder): |
|
"""My custom dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
MyDatasetConfig( |
|
name="default", |
|
description="This version of the dataset contains two types of images with metadata.", |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"listing_title": datasets.Value("string"), |
|
"url": datasets.Value("string"), |
|
"listing_image": datasets.Image(), |
|
"search_image": datasets.Image(), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage="Your dataset homepage here", |
|
license="Your dataset's license here", |
|
citation="Your dataset's citation here", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"datapath": "path_to_your_downloaded_data", |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, datapath): |
|
|
|
|
|
|
|
with open(datapath, encoding="utf-8") as csv_file: |
|
reader = csv.DictReader(csv_file) |
|
for idx, row in enumerate(reader): |
|
yield idx, { |
|
"id": row['id'], |
|
"listing_title": row['listing-title'], |
|
"url": row['url'], |
|
"listing_image": row['Listing Image'], |
|
"search_image": row['Search-image'], |
|
} |
|
|