File size: 5,335 Bytes
c50dde6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/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()