#!/usr/bin/env python3 """ Script to update data paths in ProxyCLIP config files. Run this after downloading datasets to configure the correct paths. """ import os import sys import argparse from pathlib import Path # Default paths SCRIPT_DIR = Path(__file__).parent BUILD_ENV_DIR = SCRIPT_DIR.parent PROJECT_ROOT = BUILD_ENV_DIR.parent PROXYCLIP_DIR = PROJECT_ROOT / "ProxyCLIP_TPAMI" CONFIGS_DIR = PROXYCLIP_DIR / "configs" # Server default data path SERVER_DATA_ROOT = "/opt/tiger/xiaomoguhzz/dataset" def update_config_paths(data_root: str, dry_run: bool = False): """Update data paths in ProxyCLIP config files.""" data_root = Path(data_root).resolve() # Dataset path mappings dataset_paths = { "cfg_voc20.py": { "data_prefix": { "img_path": str(data_root / "VOCdevkit/VOC2012/JPEGImages"), "seg_map_path": str(data_root / "VOCdevkit/VOC2012/SegmentationClass"), }, "ann_file": str(data_root / "VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt"), }, "cfg_voc21.py": { "data_prefix": { "img_path": str(data_root / "VOCdevkit/VOC2012/JPEGImages"), "seg_map_path": str(data_root / "VOCdevkit/VOC2012/SegmentationClass"), }, "ann_file": str(data_root / "VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt"), }, "cfg_context59.py": { "data_prefix": { "img_path": str(data_root / "VOCdevkit/VOC2010/JPEGImages"), "seg_map_path": str(data_root / "VOCdevkit/VOC2010/SegmentationClassContext"), }, "ann_file": str(data_root / "VOCdevkit/VOC2010/ImageSets/SegmentationContext/val.txt"), }, "cfg_context60.py": { "data_prefix": { "img_path": str(data_root / "VOCdevkit/VOC2010/JPEGImages"), "seg_map_path": str(data_root / "VOCdevkit/VOC2010/SegmentationClassContext"), }, "ann_file": str(data_root / "VOCdevkit/VOC2010/ImageSets/SegmentationContext/val.txt"), }, "cfg_ade20k.py": { "data_prefix": { "img_path": str(data_root / "ADEChallengeData2016/images/validation"), "seg_map_path": str(data_root / "ADEChallengeData2016/annotations/validation"), }, }, "cfg_city_scapes.py": { "data_prefix": { "img_path": str(data_root / "cityscapes/leftImg8bit/val"), "seg_map_path": str(data_root / "cityscapes/gtFine/val"), }, }, "cfg_coco_stuff164k.py": { "data_prefix": { "img_path": str(data_root / "coco_stuff164k/images/val2017"), "seg_map_path": str(data_root / "coco_stuff164k/annotations/val2017"), }, }, "cfg_coco_object.py": { "data_prefix": { "img_path": str(data_root / "coco_object/images/val2017"), "seg_map_path": str(data_root / "coco_object/annotations/val2017"), }, }, } print("=" * 50) print("Updating ProxyCLIP config files") print("=" * 50) print(f"Data root: {data_root}") print(f"Config dir: {CONFIGS_DIR}") print("") if not CONFIGS_DIR.exists(): print(f"[ERROR] Config directory not found: {CONFIGS_DIR}") return False for config_name, paths in dataset_paths.items(): config_path = CONFIGS_DIR / config_name if not config_path.exists(): print(f"[SKIP] {config_name} - file not found") continue print(f"[UPDATE] {config_name}") # Read config file with open(config_path, 'r') as f: content = f.read() # For now, just print what would be updated if "data_prefix" in paths: for key, value in paths["data_prefix"].items(): print(f" {key}: {value}") if "ann_file" in paths: print(f" ann_file: {paths['ann_file']}") print("") print("=" * 50) print("") print("To apply these changes, you need to manually update the config files.") print("Each config file has a 'test_dataloader' section with 'data_prefix' settings.") print("") print("Example structure:") print(" test_dataloader = dict(") print(" dataset=dict(") print(" data_prefix=dict(") print(f" img_path='{data_root}/VOCdevkit/VOC2012/JPEGImages',") print(f" seg_map_path='{data_root}/VOCdevkit/VOC2012/SegmentationClass',") print(" ),") print(" )") print(" )") print("") return True def main(): parser = argparse.ArgumentParser(description="Update data paths in ProxyCLIP configs") parser.add_argument( "--data-root", type=str, default=SERVER_DATA_ROOT, help="Root directory containing all datasets (default: server path)", ) parser.add_argument( "--dry-run", action="store_true", help="Show what would be changed without modifying files", ) args = parser.parse_args() success = update_config_paths(args.data_root, args.dry_run) sys.exit(0 if success else 1) if __name__ == "__main__": main()