Download rebuild/activitynet_captions.py from QLNI/shadow-assistant-data: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/datasets/QLNI/shadow-assistant-data/resolve/main/rebuild/activitynet_captions.py
- Command line
-
hf download hf://datasets/QLNI/shadow-assistant-data/rebuild/activitynet_captions.py
-
curl -L -o activitynet_captions.py https://huggingface.co/datasets/QLNI/shadow-assistant-data/resolve/main/rebuild/activitynet_captions.py
1.2 kB
| """ActivityNet Captions (licence not stated), as SHADOW picture codes. | |
| python activitynet_captions.py eye_int8.safetensors shadow_table_v1.npz out/ | |
| """ | |
| import json, os, shutil, sys | |
| from huggingface_hub import HfApi, hf_hub_download | |
| from video_codes import Eye, Shards, encode_archive, stem | |
| R = "friedrichor/ActivityNet_Captions" | |
| eye, out = Eye(sys.argv[1], sys.argv[2]), Shards(sys.argv[3], "activitynet_captions") | |
| ann = {} | |
| for f in ("activitynet_captions_train.json", "activitynet_captions_val1.json", "activitynet_captions_val2.json"): | |
| for r in json.load(open(hf_hub_download(R, f, repo_type="dataset"), encoding="utf-8")): | |
| ann.setdefault(stem(r.get("video", "")), []).append(r) | |
| parts = sorted(f for f in HfApi().list_repo_files(R, repo_type="dataset") if f.startswith("ActivityNet_Videos.tar.part-")) | |
| with open("ActivityNet_Videos.tar", "wb") as w: | |
| for f in parts: | |
| p = hf_hub_download(R, f, repo_type="dataset") | |
| shutil.copyfileobj(open(p, "rb"), w, 1 << 24) | |
| os.remove(p) | |
| encode_archive(eye, out, "ActivityNet_Videos.tar", ann, stem, "activitynet_captions", {"repo": R, "file": "ActivityNet_Videos.tar"}) | |
| os.remove("ActivityNet_Videos.tar") | |
| out.write() | |