Download tools/verify_paths.py from SamChen567/Video-XL-Pro-Union: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/datasets/SamChen567/Video-XL-Pro-Union/resolve/main/tools/verify_paths.py
- Command line
-
hf download hf://datasets/SamChen567/Video-XL-Pro-Union/tools/verify_paths.py
-
curl -L -o verify_paths.py https://huggingface.co/datasets/SamChen567/Video-XL-Pro-Union/resolve/main/tools/verify_paths.py
1.28 kB
| # Check that every media path referenced in annotations/**/*.json exists under media/. | |
| import json, glob, os, sys | |
| ROOT = '/root/datasets' | |
| os.makedirs(f'{ROOT}/tools/missing', exist_ok=True) | |
| report, total_missing = {}, 0 | |
| for f in sorted(glob.glob(f'{ROOT}/annotations/**/*.json', recursive=True)): | |
| try: | |
| d = json.load(open(f)) | |
| except Exception: | |
| continue | |
| if not isinstance(d, list) or not d or not isinstance(d[0], dict): | |
| continue | |
| paths = set() | |
| for x in d: | |
| for k in ('video', 'image'): | |
| v = x.get(k) | |
| if v: | |
| paths.update(v if isinstance(v, list) else [v]) | |
| missing = sorted(p for p in paths if not os.path.exists(f'{ROOT}/media/{p}')) | |
| rel = os.path.relpath(f, ROOT) | |
| report[rel] = {'samples': len(d), 'unique_media': len(paths), 'missing': len(missing), 'missing_examples': missing[:5]} | |
| total_missing += len(missing) | |
| print(f"{'OK ' if not missing else 'MISS'} {rel}: {len(d)} samples, {len(paths)} media, {len(missing)} missing", flush=True) | |
| with open(f'{ROOT}/tools/missing/{os.path.basename(f)}.txt', 'w') as out: | |
| out.write('\n'.join(missing)) | |
| json.dump(report, open(f'{ROOT}/tools/verify_report.json', 'w'), indent=1) | |
| print('TOTAL_MISSING', total_missing) | |