Datasets:
Size:
10K - 100K
Upload fer2013.py
Browse files- fer2013.py +55 -0
fer2013.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.kaggle.com/datasets/msambare/fer2013"
|
11 |
+
_URL = "https://huggingface.co/datasets/Jeneral/fer2013/resolve/main/"
|
12 |
+
_URLS = {
|
13 |
+
"train": _URL + "train.pt",
|
14 |
+
}
|
15 |
+
_DESCRIPTION = "A large set of images of faces with seven emotional classes"
|
16 |
+
_CITATION = """\
|
17 |
+
@TECHREPORT{Affectnet dataset,
|
18 |
+
author = {Prince Awuah Baffour},
|
19 |
+
title = {Facial Emotion Detection},
|
20 |
+
institution = {},
|
21 |
+
year = {2022}
|
22 |
+
}
|
23 |
+
"""
|
24 |
+
|
25 |
+
|
26 |
+
class fer2013(datasets.GeneratorBasedBuilder):
|
27 |
+
def _info(self):
|
28 |
+
return datasets.DatasetInfo(
|
29 |
+
description=_DESCRIPTION,
|
30 |
+
features=datasets.Features(
|
31 |
+
{
|
32 |
+
"img_bytes": datasets.Value("binary"),
|
33 |
+
"labels": datasets.features.ClassLabel(names=["angry", "disgust", "fear", "happy", "neutral", "sad", "surprise"]),
|
34 |
+
}
|
35 |
+
),
|
36 |
+
supervised_keys=("img_bytes", "labels"),
|
37 |
+
homepage=_HOMEPAGE,
|
38 |
+
citation=_CITATION,
|
39 |
+
)
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
42 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
43 |
+
return [
|
44 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
45 |
+
]
|
46 |
+
|
47 |
+
def _generate_examples(self, filepath):
|
48 |
+
"""This function returns the examples in the raw (text) form."""
|
49 |
+
logger.info("generating examples from = %s", filepath)
|
50 |
+
|
51 |
+
with Path(filepath).open("rb") as f:
|
52 |
+
examples = pickle.load(f)
|
53 |
+
|
54 |
+
for i, ex in enumerate(examples):
|
55 |
+
yield str(i), ex
|