Jeneral commited on
Commit
f5c1814
1 Parent(s): 3f82ef3

Upload fer-2013.py

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