Datasets:
Size:
10K - 100K
Commit
•
20fc6d2
1
Parent(s):
a871984
:sparkles: add builder
Browse files- cats_and_dogs.py +59 -0
cats_and_dogs.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import List
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
logger = datasets.logging.get_logger(__name__)
|
8 |
+
|
9 |
+
|
10 |
+
_HOMEPAGE = "https://www.microsoft.com/en-us/download/details.aspx?id=54765"
|
11 |
+
_URL = "https://huggingface.co/datasets/nateraw/cats-and-dogs/resolve/main/"
|
12 |
+
_URLS = {
|
13 |
+
"train": _URL + "train.pt",
|
14 |
+
}
|
15 |
+
_DESCRIPTION = "A large set of images of cats and dogs. There are 1738 corrupted images that are dropped."
|
16 |
+
_CITATION = """\
|
17 |
+
@Inproceedings (Conference){asirra-a-captcha-that-exploits-interest-aligned-manual-image-categorization,
|
18 |
+
author = {Elson, Jeremy and Douceur, John (JD) and Howell, Jon and Saul, Jared},
|
19 |
+
title = {Asirra: A CAPTCHA that Exploits Interest-Aligned Manual Image Categorization},
|
20 |
+
booktitle = {Proceedings of 14th ACM Conference on Computer and Communications Security (CCS)},
|
21 |
+
year = {2007},
|
22 |
+
month = {October},
|
23 |
+
publisher = {Association for Computing Machinery, Inc.},
|
24 |
+
url = {https://www.microsoft.com/en-us/research/publication/asirra-a-captcha-that-exploits-interest-aligned-manual-image-categorization/},
|
25 |
+
edition = {Proceedings of 14th ACM Conference on Computer and Communications Security (CCS)},
|
26 |
+
}
|
27 |
+
"""
|
28 |
+
|
29 |
+
|
30 |
+
class CatsAndDogs(datasets.GeneratorBasedBuilder):
|
31 |
+
def _info(self):
|
32 |
+
return datasets.DatasetInfo(
|
33 |
+
description=_DESCRIPTION,
|
34 |
+
features=datasets.Features(
|
35 |
+
{
|
36 |
+
"img_bytes": datasets.Value("binary"),
|
37 |
+
"labels": datasets.features.ClassLabel(names=["cat", "dog"]),
|
38 |
+
}
|
39 |
+
),
|
40 |
+
supervised_keys=("img_bytes", "labels"),
|
41 |
+
homepage=_HOMEPAGE,
|
42 |
+
citation=_CITATION,
|
43 |
+
)
|
44 |
+
|
45 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
46 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
47 |
+
return [
|
48 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
49 |
+
]
|
50 |
+
|
51 |
+
def _generate_examples(self, filepath):
|
52 |
+
"""This function returns the examples in the raw (text) form."""
|
53 |
+
logger.info("generating examples from = %s", filepath)
|
54 |
+
|
55 |
+
with Path(filepath).open("rb") as f:
|
56 |
+
examples = pickle.load(f)
|
57 |
+
|
58 |
+
for i, ex in enumerate(examples):
|
59 |
+
yield str(i), ex
|