Datasets:
Download check_json_paths.py from wakinghours/PanoVQA: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/datasets/wakinghours/PanoVQA/resolve/main/check_json_paths.py
- Command line
-
hf download hf://datasets/wakinghours/PanoVQA/check_json_paths.py
-
curl -L -o check_json_paths.py https://huggingface.co/datasets/wakinghours/PanoVQA/resolve/main/check_json_paths.py
3.18 kB
| import os | |
| import json | |
| def check_image_paths(base_dir): | |
| # 需要检查的数据集文件夹列表 | |
| datasets = ["BlendPASS", "DeepAccident", "NuScenes"] | |
| json_files = ["train.json", "val.json"] | |
| total_missing = 0 | |
| missing_details = [] | |
| print(f"开始检查目录: {base_dir} ...\n") | |
| for dataset in datasets: | |
| dataset_dir = os.path.join(base_dir, dataset) | |
| if not os.path.exists(dataset_dir): | |
| print(f"⚠️ 警告: 找不到数据集目录 {dataset_dir}") | |
| continue | |
| for json_name in json_files: | |
| json_path = os.path.join(dataset_dir, json_name) | |
| if not os.path.exists(json_path): | |
| continue | |
| print(f"正在检查文件: {os.path.relpath(json_path, base_dir)} ...") | |
| with open(json_path, 'r', encoding='utf-8') as f: | |
| try: | |
| data = json.load(f) | |
| except json.JSONDecodeError: | |
| print(f"❌ 错误: JSON解析失败 {json_path}") | |
| continue | |
| missing_in_file = 0 | |
| # 假设json是一个列表,每个元素是一个含有 'image' 键的字典 | |
| if isinstance(data, list): | |
| for item in data: | |
| img_rel_path = item.get("image") | |
| if img_rel_path: | |
| # 相对路径是相对于当前 JSON 文件的路径 | |
| # '../../Panorama/DeepAccident/...' | |
| abs_img_path = os.path.abspath(os.path.join(os.path.dirname(json_path), img_rel_path)) | |
| if not os.path.exists(abs_img_path): | |
| missing_in_file += 1 | |
| total_missing += 1 | |
| missing_details.append(f"[{dataset}/{json_name}] 缺失: {os.path.relpath(abs_img_path, base_dir)} (原始字段: {img_rel_path})") | |
| if missing_in_file > 0: | |
| print(f" ❌ 发现缺失: {missing_in_file} 张图片无法访问。") | |
| else: | |
| print(f" ✅ 完美: 所有 {len(data)} 条数据的图片均存在!") | |
| print("-" * 50) | |
| print("\n================ 检查报告 ================") | |
| if total_missing == 0: | |
| print("🎉 恭喜!所有的 JSON 文件里的图片都能找到!") | |
| else: | |
| print(f"⚠️ 警告!总共发现了 {total_missing} 处图片缺失。") | |
| print("前 20 条缺失详情如下:") | |
| for detail in missing_details[:20]: | |
| print(f" - {detail}") | |
| if total_missing > 20: | |
| print(f" ... 以及其他 {total_missing - 20} 条。") | |
| # 将缺失文件保存为日志 | |
| log_path = os.path.join(base_dir, "missing_images.log") | |
| with open(log_path, 'w', encoding='utf-8') as lg: | |
| lg.write('\n'.join(missing_details)) | |
| print(f"\n📝 完整的缺失列表已保存至: {log_path}") | |
| if __name__ == "__main__": | |
| BASE_DIR = "/home/hk-project-pai00053/wd1434/programmes/PLM/PanoVQA/PanoVQA" | |
| check_image_paths(BASE_DIR) | |