59 lines
2.0 KiB
Python
Executable File
59 lines
2.0 KiB
Python
Executable File
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "web_dehaze"))
|
|
|
|
import pipeline # noqa: E402
|
|
|
|
|
|
DEFAULT_METHODS = ["AOD", "Baidu_API", "DCP", "DehazeNet", "GCANet", "RefineDNet"]
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Verify dehaze models through the unified pipeline.")
|
|
parser.add_argument("--images", nargs="*", help="Image names under 待去雾图片/. Defaults to all images.")
|
|
parser.add_argument("--methods", nargs="*", default=DEFAULT_METHODS, help="Methods to run.")
|
|
parser.add_argument("--skip-baidu", action="store_true", help="Skip Baidu API calls.")
|
|
args = parser.parse_args()
|
|
|
|
images = args.images or [item["name"] for item in pipeline.list_images()]
|
|
methods = [m for m in args.methods if not (args.skip_baidu and m == "Baidu_API")]
|
|
|
|
caps = pipeline.capabilities()["methods"]
|
|
unavailable = [m for m in methods if not caps.get(m, {}).get("available")]
|
|
if unavailable:
|
|
print("Unavailable methods:", ", ".join(unavailable))
|
|
return 2
|
|
|
|
failures: list[tuple[str, str, str]] = []
|
|
for image in images:
|
|
print(f"\n=== {image} ===")
|
|
for method in methods:
|
|
start = time.time()
|
|
print(f"[RUN] {method}")
|
|
try:
|
|
result = pipeline.run_dehaze_method(image, method, {}, print)
|
|
elapsed = time.time() - start
|
|
print(f"[OK] {method}: {pipeline.relpath(result)} ({elapsed:.1f}s)")
|
|
except Exception as exc:
|
|
failures.append((image, method, str(exc)))
|
|
print(f"[FAIL] {method}: {exc}")
|
|
|
|
if failures:
|
|
print("\nFailures:")
|
|
for image, method, error in failures:
|
|
print(f"- {image} / {method}: {error}")
|
|
return 1
|
|
|
|
print("\nAll requested methods completed successfully.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|