JasonCoderMaker commited on
Commit
520acfe
·
verified ·
1 Parent(s): 5408e3c

Add download_features.py

Browse files
Files changed (1) hide show
  1. download_features.py +259 -0
download_features.py ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Download GRDR-TVR dataset components from Hugging Face Hub.
4
+
5
+ This script provides a convenient way to download specific components
6
+ of the GRDR-TVR dataset including InternVideo2 features, GRDR checkpoints,
7
+ and Xpool reranker models.
8
+
9
+ Examples:
10
+ # Download everything
11
+ python download_features.py --all
12
+
13
+ # Download only features for MSR-VTT and ActivityNet
14
+ python download_features.py --features --datasets msrvtt actnet
15
+
16
+ # Download GRDR checkpoints for all datasets
17
+ python download_features.py --grdr
18
+
19
+ # Download Xpool reranker for specific dataset
20
+ python download_features.py --xpool --datasets msrvtt
21
+ """
22
+
23
+ import argparse
24
+ import os
25
+ from pathlib import Path
26
+ from huggingface_hub import snapshot_download, hf_hub_download
27
+ from tqdm import tqdm
28
+
29
+
30
+ REPO_ID = "JasonCoderMaker/GRDR-TVR"
31
+ DATASETS = ["msrvtt", "actnet", "didemo", "lsmdc"]
32
+
33
+
34
+ def download_internvideo2_features(datasets, output_dir="./dataset/features"):
35
+ """Download InternVideo2 pre-extracted features."""
36
+ print(f"\n{'='*70}")
37
+ print("📥 Downloading InternVideo2 Features")
38
+ print(f"{'='*70}\n")
39
+
40
+ features_dir = Path(output_dir) / "InternVideo2"
41
+ features_dir.mkdir(parents=True, exist_ok=True)
42
+
43
+ for dataset in datasets:
44
+ print(f"\n📦 Downloading {dataset} features...")
45
+ try:
46
+ snapshot_download(
47
+ repo_id=REPO_ID,
48
+ repo_type="dataset",
49
+ allow_patterns=f"InternVideo2/{dataset}/*",
50
+ local_dir=output_dir,
51
+ local_dir_use_symlinks=False,
52
+ )
53
+ print(f"✓ {dataset} features downloaded to {features_dir / dataset}")
54
+ except Exception as e:
55
+ print(f"✗ Error downloading {dataset} features: {e}")
56
+
57
+
58
+ def download_grdr_checkpoints(datasets, output_dir="./output"):
59
+ """Download GRDR model checkpoints."""
60
+ print(f"\n{'='*70}")
61
+ print("📥 Downloading GRDR Checkpoints")
62
+ print(f"{'='*70}\n")
63
+
64
+ grdr_dir = Path(output_dir) / "GRDR"
65
+ grdr_dir.mkdir(parents=True, exist_ok=True)
66
+
67
+ for dataset in datasets:
68
+ print(f"\n📦 Downloading {dataset} GRDR checkpoint...")
69
+ try:
70
+ snapshot_download(
71
+ repo_id=REPO_ID,
72
+ repo_type="dataset",
73
+ allow_patterns=f"GRDR/{dataset}/**",
74
+ local_dir=output_dir,
75
+ local_dir_use_symlinks=False,
76
+ )
77
+ print(f"✓ {dataset} GRDR checkpoint downloaded to {grdr_dir / dataset}")
78
+ except Exception as e:
79
+ print(f"✗ Error downloading {dataset} GRDR checkpoint: {e}")
80
+
81
+
82
+ def download_xpool_checkpoints(datasets, output_dir="./reranker/xpool/ckpt"):
83
+ """Download Xpool reranker checkpoints."""
84
+ print(f"\n{'='*70}")
85
+ print("📥 Downloading Xpool Reranker Checkpoints")
86
+ print(f"{'='*70}\n")
87
+
88
+ xpool_dir = Path(output_dir)
89
+ xpool_dir.mkdir(parents=True, exist_ok=True)
90
+
91
+ xpool_files = {
92
+ "actnet": "actnet_model_best.pth",
93
+ "didemo": "didemo_model_best.pth",
94
+ "lsmdc": "lsmdc_model_best.pth",
95
+ "msrvtt": "msrvtt9k_model_best.pth",
96
+ }
97
+
98
+ for dataset in datasets:
99
+ if dataset not in xpool_files:
100
+ print(f"⊘ Skipping {dataset} (no Xpool checkpoint)")
101
+ continue
102
+
103
+ filename = xpool_files[dataset]
104
+ print(f"\n📦 Downloading {dataset} Xpool checkpoint...")
105
+
106
+ try:
107
+ file_path = hf_hub_download(
108
+ repo_id=REPO_ID,
109
+ repo_type="dataset",
110
+ filename=f"Xpool/{filename}",
111
+ local_dir=xpool_dir.parent.parent,
112
+ local_dir_use_symlinks=False,
113
+ )
114
+ print(f"✓ {dataset} Xpool checkpoint downloaded to {xpool_dir / filename}")
115
+ except Exception as e:
116
+ print(f"✗ Error downloading {dataset} Xpool checkpoint: {e}")
117
+
118
+
119
+ def download_scripts(output_dir="./scripts"):
120
+ """Download utility scripts."""
121
+ print(f"\n{'='*70}")
122
+ print("📥 Downloading Utility Scripts")
123
+ print(f"{'='*70}\n")
124
+
125
+ scripts_dir = Path(output_dir)
126
+ scripts_dir.mkdir(parents=True, exist_ok=True)
127
+
128
+ script_files = [
129
+ "download_features.py",
130
+ "download_checkpoints.sh",
131
+ ]
132
+
133
+ for script in script_files:
134
+ try:
135
+ file_path = hf_hub_download(
136
+ repo_id=REPO_ID,
137
+ repo_type="dataset",
138
+ filename=script,
139
+ local_dir=".",
140
+ local_dir_use_symlinks=False,
141
+ )
142
+ print(f"✓ {script} downloaded")
143
+ except Exception as e:
144
+ print(f"⊘ {script} not available: {e}")
145
+
146
+
147
+ def main():
148
+ parser = argparse.ArgumentParser(
149
+ description="Download GRDR-TVR dataset components from Hugging Face Hub",
150
+ formatter_class=argparse.RawDescriptionHelpFormatter,
151
+ epilog="""
152
+ Examples:
153
+ # Download everything for all datasets
154
+ python download_features.py --all
155
+
156
+ # Download only InternVideo2 features for MSR-VTT
157
+ python download_features.py --features --datasets msrvtt
158
+
159
+ # Download GRDR checkpoints for MSR-VTT and ActivityNet
160
+ python download_features.py --grdr --datasets msrvtt actnet
161
+
162
+ # Download all components for DiDeMo
163
+ python download_features.py --all --datasets didemo
164
+ """
165
+ )
166
+
167
+ # Component selection
168
+ parser.add_argument(
169
+ "--all",
170
+ action="store_true",
171
+ help="Download all components (features, GRDR, Xpool)",
172
+ )
173
+ parser.add_argument(
174
+ "--features",
175
+ action="store_true",
176
+ help="Download InternVideo2 features",
177
+ )
178
+ parser.add_argument(
179
+ "--grdr",
180
+ action="store_true",
181
+ help="Download GRDR model checkpoints",
182
+ )
183
+ parser.add_argument(
184
+ "--xpool",
185
+ action="store_true",
186
+ help="Download Xpool reranker checkpoints",
187
+ )
188
+ parser.add_argument(
189
+ "--scripts",
190
+ action="store_true",
191
+ help="Download utility scripts",
192
+ )
193
+
194
+ # Dataset selection
195
+ parser.add_argument(
196
+ "--datasets",
197
+ nargs="+",
198
+ choices=DATASETS,
199
+ default=DATASETS,
200
+ help="Datasets to download (default: all)",
201
+ )
202
+
203
+ # Output directories
204
+ parser.add_argument(
205
+ "--features-dir",
206
+ type=str,
207
+ default="./dataset/features",
208
+ help="Output directory for features (default: ./dataset/features)",
209
+ )
210
+ parser.add_argument(
211
+ "--grdr-dir",
212
+ type=str,
213
+ default="./output",
214
+ help="Output directory for GRDR checkpoints (default: ./output)",
215
+ )
216
+ parser.add_argument(
217
+ "--xpool-dir",
218
+ type=str,
219
+ default="./reranker/xpool/ckpt",
220
+ help="Output directory for Xpool checkpoints (default: ./reranker/xpool/ckpt)",
221
+ )
222
+
223
+ args = parser.parse_args()
224
+
225
+ # Validate: at least one component must be selected
226
+ if not any([args.all, args.features, args.grdr, args.xpool, args.scripts]):
227
+ parser.error("Please specify at least one component: --all, --features, --grdr, --xpool, or --scripts")
228
+
229
+ print(f"\n{'='*70}")
230
+ print(f"GRDR-TVR Dataset Downloader")
231
+ print(f"{'='*70}")
232
+ print(f"Repository: {REPO_ID}")
233
+ print(f"Datasets: {', '.join(args.datasets)}")
234
+ print(f"{'='*70}\n")
235
+
236
+ # Download components
237
+ if args.all or args.features:
238
+ download_internvideo2_features(args.datasets, args.features_dir)
239
+
240
+ if args.all or args.grdr:
241
+ download_grdr_checkpoints(args.datasets, args.grdr_dir)
242
+
243
+ if args.all or args.xpool:
244
+ download_xpool_checkpoints(args.datasets, args.xpool_dir)
245
+
246
+ if args.scripts:
247
+ download_scripts()
248
+
249
+ print(f"\n{'='*70}")
250
+ print("✓ Download Complete!")
251
+ print(f"{'='*70}\n")
252
+ print("Next steps:")
253
+ print("1. Verify downloads in the output directories")
254
+ print("2. See README.md for usage instructions")
255
+ print(f"3. Visit https://huggingface.co/datasets/{REPO_ID} for more details\n")
256
+
257
+
258
+ if __name__ == "__main__":
259
+ main()