forked from shubham-monarch/sbevnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
executable file
·96 lines (75 loc) · 2.75 KB
/
Copy pathdebug.py
File metadata and controls
executable file
·96 lines (75 loc) · 2.75 KB
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
#! /usr/bin/env python3
import logging
from typing import Callable, Dict
from dataclasses import dataclass
import traceback
from pathlib import Path
import argparse
from helpers import get_logger
logger = get_logger("debug")
@dataclass
class DebugCase:
"""Class to represent a debug test case"""
name: str
description: str
function: Callable
enabled: bool = True
class DebugRunner:
"""Class to manage and run debug test cases"""
def __init__(self):
self.cases: Dict[str, DebugCase] = {}
self.debug_dir = Path("debug")
def register_case(self, case_id: str, name: str, description: str, func: Callable, enabled: bool = True) -> None:
"""Register a new debug case"""
self.cases[case_id] = DebugCase(name, description, func, enabled)
def run_case(self, case_id: str) -> None:
"""Run a specific debug case"""
if case_id not in self.cases:
logger.error(f"Case {case_id} not found")
return
case = self.cases[case_id]
if not case.enabled:
logger.info(f"Case {case_id} ({case.name}) is disabled, skipping...")
return
logger.info(f"Running case {case_id}: {case.name}")
logger.info(f"Description: {case.description}")
logger.info("=" * 50)
try:
case.function()
except Exception as e:
logger.error(f"Error in case {case_id}: {str(e)}")
logger.error(traceback.format_exc())
logger.info("=" * 50)
def run_all_enabled(self) -> None:
"""Run all enabled debug cases"""
for case_id in self.cases:
self.run_case(case_id)
def get_case_dir(self, case_id: str) -> Path:
"""Get directory for debug case outputs"""
case_dir = self.debug_dir / case_id
case_dir.mkdir(parents=True, exist_ok=True)
return case_dir
# Define debug cases in separate module
from debug_cases import (
test_labels_in_seg_masks
)
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description='Run debug test cases')
parser.add_argument('--case', type=str, help='Specific case ID to run')
args = parser.parse_args()
# Initialize debug runner
runner = DebugRunner()
# Register all test cases
cases = [
("case_1", "Dairy Masks", "Test dairy mask generation", test_labels_in_seg_masks),
]
for case_id, name, desc, func in cases:
runner.register_case(case_id, name, desc, func)
# Run specific case if provided, otherwise run all cases
if args.case:
runner.run_case(args.case)
else:
runner.run_all_enabled()
if __name__ == "__main__":
main()