Leyo commited on
Commit
6d26ce9
·
1 Parent(s): b37dcf1

download from original website

Browse files
Files changed (1) hide show
  1. TGIF.py +30 -31
TGIF.py CHANGED
@@ -3,6 +3,7 @@
3
 
4
  import csv
5
  import datasets
 
6
 
7
  _CITATION = """
8
  @InProceedings{tgif-cvpr2016,
@@ -24,7 +25,7 @@ and three sentences per GIF for the test split. The dataset shall be used to eva
24
 
25
  _URL_BASE = "http://raingo.github.io/TGIF-Release/"
26
 
27
- _DL_URL = "https://huggingface.co/datasets/Leyo/TGIF/resolve/main/data.tar.gz"
28
 
29
 
30
  class TGIFConfig(datasets.BuilderConfig):
@@ -47,7 +48,7 @@ class TGIF(datasets.GeneratorBasedBuilder):
47
  description=_DESCRIPTION,
48
  features=datasets.Features(
49
  {
50
- "video_path": datasets.Value("string"),
51
  "captions": datasets.features.Sequence(datasets.Value("string"))
52
  }
53
  ),
@@ -57,13 +58,16 @@ class TGIF(datasets.GeneratorBasedBuilder):
57
  )
58
 
59
  def _split_generators(self, dl_manager):
60
- archive_path = dl_manager.download(_DL_URL)
 
 
 
61
  train_splits = [
62
  datasets.SplitGenerator(
63
  name=datasets.Split.TRAIN,
64
  gen_kwargs={
65
- "files": dl_manager.iter_archive(archive_path),
66
- "split": "train"
67
  },
68
  )
69
  ]
@@ -71,8 +75,8 @@ class TGIF(datasets.GeneratorBasedBuilder):
71
  datasets.SplitGenerator(
72
  name=datasets.Split.VALIDATION,
73
  gen_kwargs={
74
- "files": dl_manager.iter_archive(archive_path),
75
- "split": "dev"
76
  },
77
  )
78
  ]
@@ -80,36 +84,31 @@ class TGIF(datasets.GeneratorBasedBuilder):
80
  datasets.SplitGenerator(
81
  name=datasets.Split.TEST,
82
  gen_kwargs={
83
- "files": dl_manager.iter_archive(archive_path),
84
- "split": "test"
85
  },
86
  )
87
  ]
88
  return train_splits + dev_splits + test_splits
89
 
90
- def _generate_examples(self, files, split):
91
  """This function returns the examples."""
92
 
93
  dict = {}
94
- for path, f in files:
95
- if path.endswith(split + ".txt"):
96
- txt_file = f.read().decode("utf-8").split("\n")
97
- for line in txt_file:
98
- line = line
99
  dict[line] = []
100
- for path, f in files:
101
- if path.endswith("tgif-v1.0.tsv"):
102
- tsv_file = f.read().decode("utf-8").split("\n")[:-1]
103
- tsv_reader = csv.reader(
104
- tsv_file, delimiter="\t", quotechar='"')
105
- for idx, (video_path, text) in enumerate(tsv_reader):
106
- try:
107
- dict[video_path].append(text)
108
- except Exception:
109
- pass
110
-
111
- for idx, video_path in enumerate(dict):
112
- yield idx, {
113
- "video_path": video_path,
114
- "captions": dict[video_path],
115
- }
 
3
 
4
  import csv
5
  import datasets
6
+ import os
7
 
8
  _CITATION = """
9
  @InProceedings{tgif-cvpr2016,
 
25
 
26
  _URL_BASE = "http://raingo.github.io/TGIF-Release/"
27
 
28
+ _DL_URL = "https://github.com/raingo/TGIF-Release/archive/master.zip"
29
 
30
 
31
  class TGIFConfig(datasets.BuilderConfig):
 
48
  description=_DESCRIPTION,
49
  features=datasets.Features(
50
  {
51
+ "path": datasets.Value("string"),
52
  "captions": datasets.features.Sequence(datasets.Value("string"))
53
  }
54
  ),
 
58
  )
59
 
60
  def _split_generators(self, dl_manager):
61
+ archive_path = dl_manager.download_and_extract(_DL_URL)
62
+ archive_data_path = archive_path + "data/splits/"
63
+ infos_file = archive_path + "data/tgif-v1.0.tsv"
64
+
65
  train_splits = [
66
  datasets.SplitGenerator(
67
  name=datasets.Split.TRAIN,
68
  gen_kwargs={
69
+ "split_links_file": os.path.join(archive_data_path, "train.txt"),
70
+ "infos_file": infos_file
71
  },
72
  )
73
  ]
 
75
  datasets.SplitGenerator(
76
  name=datasets.Split.VALIDATION,
77
  gen_kwargs={
78
+ "split_links_file": os.path.join(archive_data_path, "dev.txt"),
79
+ "infos_file": infos_file
80
  },
81
  )
82
  ]
 
84
  datasets.SplitGenerator(
85
  name=datasets.Split.TEST,
86
  gen_kwargs={
87
+ "split_links_file": os.path.join(archive_data_path, "test.txt"),
88
+ "infos_file": infos_file
89
  },
90
  )
91
  ]
92
  return train_splits + dev_splits + test_splits
93
 
94
+ def _generate_examples(self, split_links_file, infos_file):
95
  """This function returns the examples."""
96
 
97
  dict = {}
98
+ split_links_file = "/content/TGIF-Release-master/data/splits/test.txt"
99
+ with open(split_links_file,encoding = "utf-8") as txt_file:
100
+ for line in txt_file:
101
+ line = line[0:-1]
 
102
  dict[line] = []
103
+ infos_file = "/content/TGIF-Release-master/data/tgif-v1.0.tsv"
104
+ with open(infos_file, encoding="utf-8") as tsv_file:
105
+ tsv_reader = csv.reader(tsv_file, delimiter="\t", quotechar='"' )
106
+ for idx, (video_link, text) in enumerate(tsv_reader):
107
+ try:
108
+ dict[video_link].append(text)
109
+ except Exception:
110
+ pass
111
+ yield idx, {
112
+ "path": video_link,
113
+ "captions": text,
114
+ }