dinggd commited on
Commit
b38a0d8
1 Parent(s): fdc859f

Create gtea.py

Browse files
Files changed (1) hide show
  1. gtea.py +117 -0
gtea.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import datasets
3
+
4
+ import numpy as np
5
+
6
+ _DESCRIPTION = """\
7
+ GTEA is composed of 50 recorded videos of 25 participants making two different mixed salads. The videos are captured by a camera with a top-down view onto the work-surface. The participants are provided with recipe steps which are randomly sampled from a statistical recipe model.
8
+ """
9
+
10
+ _CITATION = """\
11
+ @inproceedings{stein2013combining,
12
+ title={Combining embedded accelerometers with computer vision for recognizing food preparation activities},
13
+ author={Stein, Sebastian and McKenna, Stephen J},
14
+ booktitle={Proceedings of the 2013 ACM international joint conference on Pervasive and ubiquitous computing},
15
+ pages={729--738},
16
+ year={2013}
17
+ }
18
+ """
19
+
20
+ _HOMEPAGE = ""
21
+
22
+ _LICENSE = "xxx"
23
+
24
+ _URLS = {"full": "https://huggingface.co/datasets/dinggd/gtea/resolve/main/gtea.zip"}
25
+
26
+
27
+ class GTEA(datasets.GeneratorBasedBuilder):
28
+
29
+ VERSION = datasets.Version("1.0.0")
30
+
31
+ BUILDER_CONFIGS = [
32
+ datasets.BuilderConfig(
33
+ name="split1", version=VERSION, description="Cross Validation Split1"
34
+ ),
35
+ datasets.BuilderConfig(
36
+ name="split2", version=VERSION, description="Cross Validation Split2"
37
+ ),
38
+ datasets.BuilderConfig(
39
+ name="split3", version=VERSION, description="Cross Validation Split3"
40
+ ),
41
+ datasets.BuilderConfig(
42
+ name="split4", version=VERSION, description="Cross Validation Split4"
43
+ ),
44
+ ]
45
+
46
+ DEFAULT_CONFIG_NAME = "1"
47
+
48
+ def _info(self):
49
+ features = datasets.Features(
50
+ {
51
+ "video_id": datasets.Value("string"),
52
+ "video_feature": datasets.Array2D(shape=(None, 2048), dtype="float32"),
53
+ "video_label": datasets.Sequence(datasets.Value(dtype="int32")),
54
+ }
55
+ )
56
+
57
+ return datasets.DatasetInfo(
58
+ description=_DESCRIPTION,
59
+ features=features,
60
+ homepage=_HOMEPAGE,
61
+ license=_LICENSE,
62
+ citation=_CITATION,
63
+ )
64
+
65
+ def _split_generators(self, dl_manager):
66
+ urls_to_download = _URLS
67
+ data_dir = dl_manager.download_and_extract(urls_to_download)["full"]
68
+ return [
69
+ datasets.SplitGenerator(
70
+ name=datasets.Split.TRAIN,
71
+ gen_kwargs={
72
+ "filepath": os.path.join(
73
+ data_dir, f"gtea/splits/train.{self.config.name}.bundle"
74
+ ),
75
+ "featurefolder": os.path.join(data_dir, "gtea/features"),
76
+ "gtfolder": os.path.join(data_dir, "gtea/groundTruth"),
77
+ "mappingpath": os.path.join(data_dir, "gtea/mapping.txt"),
78
+ },
79
+ ),
80
+ datasets.SplitGenerator(
81
+ name=datasets.Split.TEST,
82
+ gen_kwargs={
83
+ "filepath": os.path.join(
84
+ data_dir, f"gtea/splits/test.{self.config.name}.bundle"
85
+ ),
86
+ "featurefolder": os.path.join(data_dir, "gtea/features"),
87
+ "gtfolder": os.path.join(data_dir, "gtea/groundTruth"),
88
+ "mappingpath": os.path.join(data_dir, "gtea/mapping.txt"),
89
+ },
90
+ ),
91
+ ]
92
+
93
+ def _generate_examples(self, filepath, featurefolder, gtfolder, mappingpath):
94
+ with open(mappingpath, "r") as f:
95
+ actions = f.read().splitlines()
96
+ actions_dict = {}
97
+ for a in actions:
98
+ actions_dict[a.split()[1]] = int(a.split()[0])
99
+
100
+ with open(filepath, "r") as f:
101
+ lines = f.read().splitlines()
102
+ for key, line in enumerate(lines):
103
+ vid = line[:-4]
104
+ featurepath = os.path.join(featurefolder, f"{vid}.npy")
105
+ gtpath = os.path.join(gtfolder, line)
106
+ feature = np.load(featurepath).T # T x D
107
+ with open(gtpath, "r") as f:
108
+ content = f.read().splitlines()
109
+
110
+ label = np.zeros(min(np.shape(feature)[1], len(content)))
111
+ for i in range(len(label)):
112
+ label[i] = actions_dict[content[i]]
113
+ yield key, {
114
+ "video_id": vid,
115
+ "video_feature": feature,
116
+ "video_label": label,
117
+ }