VictorSanh HF staff commited on
Commit
c954cad
1 Parent(s): 1e312e6

include action recognition and multi instance retrieval

Browse files
Files changed (1) hide show
  1. epic_kitchens_100.py +78 -75
epic_kitchens_100.py CHANGED
@@ -14,7 +14,11 @@
14
  # limitations under the License.
15
 
16
  # Lint as: python3
17
- """"""
 
 
 
 
18
 
19
  import os
20
  import csv
@@ -49,11 +53,22 @@ in the kitchen over multiple days. Annotations are collected using a novel 'Paus
49
  EPIC-KITCHENS-100 is an extension of the EPIC-KITCHENS dataset released in 2018, to 100 hours of footage.
50
  """
51
 
 
 
 
 
52
  _URL_BASE = "https://raw.githubusercontent.com/epic-kitchens/epic-kitchens-100-annotations/master/"
53
 
54
 
 
 
 
 
55
  class EpicKitchens100(datasets.GeneratorBasedBuilder):
56
- """"""
 
 
 
57
 
58
  def _info(self):
59
  return datasets.DatasetInfo(
@@ -64,117 +79,105 @@ class EpicKitchens100(datasets.GeneratorBasedBuilder):
64
  "narration_id": datasets.Value("string"),
65
  "participant_id": datasets.Value("string"),
66
  "video_id": datasets.Value("string"),
 
67
  "narration_timestamp": datasets.Value("string"),
68
  "start_timestamp": datasets.Value("string"),
69
  "stop_timestamp": datasets.Value("string"),
70
- # "start_frame": datasets.Value("int32"),
71
- # "stop_frame": datasets.Value("int32"),
72
  "narration": datasets.Value("string"),
73
  "verb": datasets.Value("string"),
74
- "verb_class": datasets.Value("int32"), # More info: https://github.com/epic-kitchens/epic-kitchens-100-annotations/blob/master/README.md#epic_100_noun_classescsv
 
75
  "noun": datasets.Value("string"),
76
- "noun_class": datasets.Value("string"), # More info: https://github.com/epic-kitchens/epic-kitchens-100-annotations/blob/master/README.md#epic_100_noun_classescsv
 
77
  "all_nouns": datasets.features.Sequence(datasets.Value("string")),
78
  "all_noun_classes": datasets.features.Sequence(datasets.Value("int32")),
79
  }
80
  ),
81
  supervised_keys=None,
82
- homepage="https://epic-kitchens.github.io/2022",
83
  citation=_CITATION,
 
84
  )
85
 
86
  def _split_generators(self, dl_manager):
87
  urls = {
88
- "annotations": {
89
  "train": os.path.join(_URL_BASE, "EPIC_100_train.csv"),
90
  "validation": os.path.join(_URL_BASE, "EPIC_100_validation.csv"),
91
  "test": os.path.join(_URL_BASE, "EPIC_100_test_timestamps.csv"),
92
  },
93
- # "verb_and_noun_classes": {
94
- # "verb": os.path.join(_URL_BASE, "EPIC_100_verb_classes.csv"),
95
- # "noun": os.path.join(_URL_BASE, "EPIC_100_noun_classes.csv")
96
- # }
97
  }
98
  files_path = dl_manager.download_and_extract(urls)
99
- return [
100
  datasets.SplitGenerator(
101
  name=datasets.Split.TRAIN,
102
  gen_kwargs={
103
- "annotations": files_path["annotations"]["train"],
104
  "split": "train",
105
  },
106
  ),
107
- datasets.SplitGenerator(
108
- name=datasets.Split.VALIDATION,
109
- gen_kwargs={
110
- "annotations": files_path["annotations"]["validation"],
111
- "split": "validation",
112
- },
113
- ),
114
  datasets.SplitGenerator(
115
  name=datasets.Split.TEST,
116
  gen_kwargs={
117
- "annotations": files_path["annotations"]["test"],
118
  "split": "test",
119
  },
120
  ),
121
  ]
122
-
123
- # def _get_instances_mapping(self, file):
124
- # mapping = {}
125
- # with open(file, encoding="utf-8") as f:
126
- # csv_reader = csv.reader(f, delimiter=",")
127
- # next(csv_reader)
128
- # for id, key, instances, category in csv_reader:
129
- # mapping[int(id)] = {
130
- # "key": key,
131
- # "instances": instances,
132
- # "category": category,
133
- # }
134
- # return mapping
135
 
136
  def _generate_examples(self, annotations, split):
137
  """This function returns the examples."""
138
  with open(annotations, encoding="utf-8") as csv_file:
139
  csv_reader = csv.reader(csv_file, delimiter=",")
140
  next(csv_reader) # Skip header
141
- if split != "test":
142
- for idx, row in enumerate(csv_reader):
143
- yield idx, {
144
- "extended": len(row[0].split("_")[1]) == 3,
145
- "narration_id": row[0],
146
- "participant_id": row[1],
147
- "video_id": row[2],
148
- "narration_timestamp": row[3],
149
- "start_timestamp": row[4],
150
- "stop_timestamp": row[5],
151
- # "start_frame": row[6],
152
- # "stop_frame": row[7],
153
- "narration": row[8],
154
- "verb": row[9],
155
- "verb_class": row[10],
156
- "noun": row[11],
157
- "noun_class": row[12],
158
- "all_nouns": eval(row[13]),
159
- "all_noun_classes": eval(row[14]),
160
- }
161
- else:
162
- for idx, row in enumerate(csv_reader):
163
- yield idx, {
164
- "extended": len(row[0].split("_")[1]) == 3,
165
- "narration_id": row[0],
166
- "participant_id": row[1],
167
- "video_id": row[2],
168
- "narration_timestamp": row[3],
169
- "start_timestamp": row[4],
170
- "stop_timestamp": row[5],
171
- # "start_frame": row[6],
172
- # "stop_frame": row[7],
173
- "narration": "",
174
- "verb": "",
175
- "verb_class": -1,
176
- "noun": "",
177
- "noun_class": -1,
178
- "all_nouns": [],
179
- "all_noun_classes": [],
180
- }
14
  # limitations under the License.
15
 
16
  # Lint as: python3
17
+ """EPIC-KITCHENS-100 is a large-scale dataset in first-person (egocentric) vision; multi-faceted, audio-visual,
18
+ non-scripted recordings in native environments - i.e. the wearers' homes, capturing all daily activities
19
+ in the kitchen over multiple days. Annotations are collected using a novel 'Pause-and-Talk' narration interface.
20
+
21
+ EPIC-KITCHENS-100 is an extension of the EPIC-KITCHENS dataset released in 2018, to 100 hours of footage."""
22
 
23
  import os
24
  import csv
53
  EPIC-KITCHENS-100 is an extension of the EPIC-KITCHENS dataset released in 2018, to 100 hours of footage.
54
  """
55
 
56
+ _HOMEPAGE = "https://epic-kitchens.github.io/2022"
57
+
58
+ _LICENSE = "CC BY-NC 4.0"
59
+
60
  _URL_BASE = "https://raw.githubusercontent.com/epic-kitchens/epic-kitchens-100-annotations/master/"
61
 
62
 
63
+ _VARIANTS = [
64
+ "action_recognition", # This split is used by four challenges: Action Recognition, Weakly supervised action recognition, Action detection, Action anticipation
65
+ "multi_instance_retrieval",
66
+ ]
67
  class EpicKitchens100(datasets.GeneratorBasedBuilder):
68
+ """Epic Kitchens"""
69
+
70
+ BUILDER_CONFIGS = [datasets.BuilderConfig(name) for name in _VARIANTS]
71
+ DEFAULT_CONFIG_NAME = "action_recognition"
72
 
73
  def _info(self):
74
  return datasets.DatasetInfo(
79
  "narration_id": datasets.Value("string"),
80
  "participant_id": datasets.Value("string"),
81
  "video_id": datasets.Value("string"),
82
+ "path": datasets.Value("string"),
83
  "narration_timestamp": datasets.Value("string"),
84
  "start_timestamp": datasets.Value("string"),
85
  "stop_timestamp": datasets.Value("string"),
 
 
86
  "narration": datasets.Value("string"),
87
  "verb": datasets.Value("string"),
88
+ "verb_class": datasets.Value("int32"),
89
+ # The mapping for `verb_class` is available at: https://github.com/epic-kitchens/epic-kitchens-100-annotations/blob/master/README.md#epic_100_noun_classescsv
90
  "noun": datasets.Value("string"),
91
+ "noun_class": datasets.Value("string"),
92
+ # The mapping for `noun_class` is available at: https://github.com/epic-kitchens/epic-kitchens-100-annotations/blob/master/README.md#epic_100_noun_classescsv
93
  "all_nouns": datasets.features.Sequence(datasets.Value("string")),
94
  "all_noun_classes": datasets.features.Sequence(datasets.Value("int32")),
95
  }
96
  ),
97
  supervised_keys=None,
98
+ homepage=_HOMEPAGE,
99
  citation=_CITATION,
100
+ license=_LICENSE
101
  )
102
 
103
  def _split_generators(self, dl_manager):
104
  urls = {
105
+ "action_recognition": {
106
  "train": os.path.join(_URL_BASE, "EPIC_100_train.csv"),
107
  "validation": os.path.join(_URL_BASE, "EPIC_100_validation.csv"),
108
  "test": os.path.join(_URL_BASE, "EPIC_100_test_timestamps.csv"),
109
  },
110
+ "multi_instance_retrieval": {
111
+ "train": os.path.join(_URL_BASE, "retrieval_annotations/EPIC_100_retrieval_train.csv"),
112
+ "test": os.path.join(_URL_BASE, "retrieval_annotations/EPIC_100_retrieval_test.csv")
113
+ }
114
  }
115
  files_path = dl_manager.download_and_extract(urls)
116
+ splits = [
117
  datasets.SplitGenerator(
118
  name=datasets.Split.TRAIN,
119
  gen_kwargs={
120
+ "annotations": files_path[self.config.name]["train"],
121
  "split": "train",
122
  },
123
  ),
 
 
 
 
 
 
 
124
  datasets.SplitGenerator(
125
  name=datasets.Split.TEST,
126
  gen_kwargs={
127
+ "annotations": files_path[self.config.name]["test"],
128
  "split": "test",
129
  },
130
  ),
131
  ]
132
+ if self.config.name == "action_recognition":
133
+ splits.append(
134
+ datasets.SplitGenerator(
135
+ name=datasets.Split.VALIDATION,
136
+ gen_kwargs={
137
+ "annotations": files_path[self.config.name]["validation"],
138
+ "split": "validation",
139
+ },
140
+ ),
141
+ )
142
+ return splits
 
 
143
 
144
  def _generate_examples(self, annotations, split):
145
  """This function returns the examples."""
146
  with open(annotations, encoding="utf-8") as csv_file:
147
  csv_reader = csv.reader(csv_file, delimiter=",")
148
  next(csv_reader) # Skip header
149
+ for idx, row in enumerate(csv_reader):
150
+ narration_id, participant_id, video_id, narration_timestamp, start_timestamp, stop_timestamp = row[:6]
151
+ if split != "test":
152
+ # The reason why it's jumping from 5 to 8 is that we are skipping `start_frame` and `stop_frame`
153
+ # since we are not exposing the frames, but just the videos
154
+ narration, verb, verb_class, noun, noun_class, all_nouns, all_noun_classes = row[8:15]
155
+ all_nouns = eval(all_nouns)
156
+ all_noun_classes = eval(all_noun_classes)
157
+ else:
158
+ narration = verb = noun = ""
159
+ verb_class = noun_class = -1
160
+ all_nouns = all_noun_classes = []
161
+ extended = len(narration_id.split("_")[1]) == 3
162
+ if extended:
163
+ path = f"EPIC-KITCHENS/{participant_id}/videos/{video_id}.MP4" #Paths for jz version
164
+ else:
165
+ path = f"EPIC_KITCHENS_2018/videos/{split}/{participant_id}/{video_id}.MP4" #Paths for jz version
166
+
167
+ yield idx, {
168
+ "extended": extended,
169
+ "narration_id": narration_id,
170
+ "participant_id": participant_id,
171
+ "video_id": video_id,
172
+ "path": path,
173
+ "narration_timestamp": narration_timestamp,
174
+ "start_timestamp": start_timestamp,
175
+ "stop_timestamp": stop_timestamp,
176
+ "narration": narration,
177
+ "verb": verb,
178
+ "verb_class": verb_class,
179
+ "noun": noun,
180
+ "noun_class": noun_class,
181
+ "all_nouns": all_nouns,
182
+ "all_noun_classes": all_noun_classes,
183
+ }