Commit
·
edbad79
1
Parent(s):
e5f85c2
Upload huggingface-images.py
Browse files- huggingface-images.py +77 -0
huggingface-images.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
# Constants for your dataset
|
5 |
+
_DESCRIPTION = """\
|
6 |
+
This dataset includes images with associated IDs, titles, and URLs. There are two types of images: 'Listing Image' and 'Search-image'.
|
7 |
+
"""
|
8 |
+
_LABEL_MAP = {
|
9 |
+
'Listing Image': 'listing_image',
|
10 |
+
'Search-image': 'search_image',
|
11 |
+
}
|
12 |
+
|
13 |
+
class MyDatasetConfig(datasets.BuilderConfig):
|
14 |
+
"""BuilderConfig for MyDataset."""
|
15 |
+
|
16 |
+
def __init__(self, **kwargs):
|
17 |
+
"""BuilderConfig for MyDataset.
|
18 |
+
Args:
|
19 |
+
**kwargs: keyword arguments forwarded to super.
|
20 |
+
"""
|
21 |
+
super(MyDatasetConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
22 |
+
|
23 |
+
|
24 |
+
class MyDataset(datasets.GeneratorBasedBuilder):
|
25 |
+
"""My custom dataset."""
|
26 |
+
|
27 |
+
BUILDER_CONFIGS = [
|
28 |
+
MyDatasetConfig(
|
29 |
+
name="default",
|
30 |
+
description="This version of the dataset contains two types of images with metadata.",
|
31 |
+
)
|
32 |
+
]
|
33 |
+
|
34 |
+
def _info(self):
|
35 |
+
return datasets.DatasetInfo(
|
36 |
+
description=_DESCRIPTION,
|
37 |
+
features=datasets.Features(
|
38 |
+
{
|
39 |
+
"id": datasets.Value("string"),
|
40 |
+
"listing_title": datasets.Value("string"),
|
41 |
+
"url": datasets.Value("string"),
|
42 |
+
"listing_image": datasets.Image(),
|
43 |
+
"search_image": datasets.Image(),
|
44 |
+
}
|
45 |
+
),
|
46 |
+
supervised_keys=None,
|
47 |
+
homepage="Your dataset homepage here",
|
48 |
+
license="Your dataset's license here",
|
49 |
+
citation="Your dataset's citation here",
|
50 |
+
)
|
51 |
+
|
52 |
+
def _split_generators(self, dl_manager):
|
53 |
+
# You would have a way to access and download your data, for example, from a Google Cloud Storage Bucket
|
54 |
+
# For simplicity, we are assuming your data is already downloaded and accessible
|
55 |
+
return [
|
56 |
+
datasets.SplitGenerator(
|
57 |
+
name=datasets.Split.TRAIN,
|
58 |
+
gen_kwargs={
|
59 |
+
"datapath": "path_to_your_downloaded_data",
|
60 |
+
},
|
61 |
+
)
|
62 |
+
]
|
63 |
+
|
64 |
+
def _generate_examples(self, datapath):
|
65 |
+
# Here you will write the logic to read your dataset's contents
|
66 |
+
# For example, let's say you have a CSV file with all the metadata and the links to the images
|
67 |
+
# You would read the CSV file and for each row, yield the following:
|
68 |
+
with open(datapath, encoding="utf-8") as csv_file:
|
69 |
+
reader = csv.DictReader(csv_file)
|
70 |
+
for idx, row in enumerate(reader):
|
71 |
+
yield idx, {
|
72 |
+
"id": row['id'],
|
73 |
+
"listing_title": row['listing-title'],
|
74 |
+
"url": row['url'],
|
75 |
+
"listing_image": row['Listing Image'],
|
76 |
+
"search_image": row['Search-image'],
|
77 |
+
}
|