File size: 2,161 Bytes
a027087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Report import, model-wheel, CPU, CUDA, and checkpoint readiness."""

from __future__ import annotations

import importlib.metadata
import json
import sys
from pathlib import Path

BACKEND_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(BACKEND_ROOT))


def main() -> int:
    import cv2
    import numpy
    import torch
    from app.config import settings
    from basicsr.archs.rrdbnet_arch import RRDBNet
    from realesrgan import RealESRGANer
    from torchvision.ops import nms

    version_checks = {
        name: importlib.metadata.version(name)
        for name in (
            "torch",
            "torchvision",
            "basicsr",
            "realesrgan",
            "numpy",
            "Pillow",
            "opencv-python",
        )
    }
    checks = {
        "python": sys.version.split()[0],
        "python_supported": sys.version_info[:2] == (3, 11),
        "package_versions": version_checks,
        "numpy": numpy.__version__,
        "opencv": cv2.__version__,
        "torch": torch.__version__,
        "torch_cuda_build": torch.version.cuda,
        "cuda_available": torch.cuda.is_available(),
        "device_selected_by_auto": "cuda" if torch.cuda.is_available() else "cpu",
        "torchvision_cpu_operator": False,
        "cuda_compiled_operator": False,
        "model_architecture_import": RRDBNet.__name__,
        "realesrgan_import": RealESRGANer.__name__,
        "weights_path": str(settings.resolved_model_path),
        "weights_present": settings.resolved_model_path.is_file(),
    }

    boxes = torch.tensor([[0.0, 0.0, 1.0, 1.0]])
    scores = torch.tensor([0.9])
    nms(boxes, scores, 0.5)
    checks["torchvision_cpu_operator"] = True
    if checks["cuda_available"]:
        nms(boxes.cuda(), scores.cuda(), 0.5)
        checks["cuda_compiled_operator"] = True

    print(json.dumps(checks, indent=2))
    if not checks["python_supported"]:
        print(
            "Run this check using the backend Python 3.11 environment.", file=sys.stderr
        )
        return 1
    return 0 if checks["weights_present"] else 2


if __name__ == "__main__":
    raise SystemExit(main())