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