File size: 1,549 Bytes
ce209f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Check importable packages for the CD-Models training environment."""

from __future__ import annotations


REQUIRED_PACKAGES = {
    ("torch", "torch", "all models"),
    ("torchvision", "torchvision", "all models"),
    ("numpy", "numpy", "all models"),
    ("PIL", "Pillow", "all models"),
    ("cv2", "opencv-python", "all models"),
    ("yaml", "pyyaml", "all models"),
    ("tqdm", "tqdm", "weight_downloader"),
    ("timm", "timm", "TinyCD, ELGCNet, ChangeFormer"),
    ("einops", "einops", "BIT_CD, ChangeFormer"),
    ("mmengine", "mmengine==0.10.1", "ChangeMamba, Changer"),
    ("mmcv", "mmcv==2.1.0", "ChangeMamba, Changer"),
    ("mmseg", "mmsegmentation==1.2.2", "ChangeMamba, Changer"),
    ("gdown", "gdown", "weight_downloader GDrive fallback"),
}


def check_env(verbose: bool = True) -> bool:
    missing = []
    for import_name, pip_name, required_by in sorted(REQUIRED_PACKAGES):
        try:
            __import__(import_name)
            if verbose:
                print(f"  [OK] {import_name}")
        except ImportError:
            print(f"  [MISSING] {import_name} (install: pip install {pip_name}) - needed by: {required_by}")
            missing.append((import_name, pip_name))

    if missing:
        print(f"\n{len(missing)} packages missing. Install with:")
        for _, pip_name in missing:
            print(f"  pip install {pip_name}")
    else:
        print("\nAll packages present.")
    return not missing


if __name__ == "__main__":
    import sys

    sys.exit(0 if check_env(verbose=True) else 1)