Download tools/fix_annotation_paths.py from SamChen567/Video-XL-Pro-Union: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/datasets/SamChen567/Video-XL-Pro-Union/resolve/main/tools/fix_annotation_paths.py
- Command line
-
hf download hf://datasets/SamChen567/Video-XL-Pro-Union/tools/fix_annotation_paths.py
-
curl -L -o fix_annotation_paths.py https://huggingface.co/datasets/SamChen567/Video-XL-Pro-Union/resolve/main/tools/fix_annotation_paths.py
976 Bytes
| # Rewrite annotation media paths so that every path resolves relative to media/. | |
| import json, glob, os | |
| A = '/root/datasets/annotations' | |
| def rewrite(path, fn, drop=None): | |
| d = json.load(open(path)) | |
| n0 = len(d) | |
| if drop: | |
| d = [x for x in d if not drop(x)] | |
| for x in d: | |
| for k in ('video', 'image'): | |
| if k in x and x[k]: | |
| x[k] = [fn(v) for v in x[k]] if isinstance(x[k], list) else fn(x[k]) | |
| tmp = path + '.tmp' | |
| json.dump(d, open(tmp, 'w'), ensure_ascii=False) | |
| os.replace(tmp, path) | |
| print(os.path.basename(path), n0, '->', len(d)) | |
| def add_prefix(p): | |
| return p if p.startswith('LLaVA178k/') else 'LLaVA178k/' + p | |
| for f in sorted(glob.glob(f'{A}/llava_video_178k/*.json')): | |
| rewrite(f, add_prefix) | |
| rewrite(f'{A}/sft/activitynetqa_15k.json', add_prefix) | |
| rewrite(f'{A}/sft/mmdu_45k.json', lambda p: p.lstrip('/')) | |
| rewrite(f'{A}/sft/finevideo_43k.json', lambda p: p, drop=lambda x: not x['conversations']) | |