msIntui commited on
Commit
dec92fd
·
1 Parent(s): 589b914

Fix import order in line_detection_ai.py

Browse files
Files changed (1) hide show
  1. line_detection_ai.py +41 -52
line_detection_ai.py CHANGED
@@ -1,61 +1,50 @@
1
- from base import BaseDetector, BaseDetectionPipeline
2
- from utils import *
3
- from config import (
4
- ImageConfig,
5
- SymbolConfig,
6
- TagConfig,
7
- LineConfig,
8
- PointConfig,
9
- JunctionConfig
10
- )
11
- from detectors import (
12
- LineDetector,
13
- PointDetector,
14
- JunctionDetector,
15
- SymbolDetector,
16
- TagDetector
17
- )
18
- from pathlib import Path
19
- from storage import StorageFactory
20
- from common import DetectionResult
21
- from detection_schema import DetectionContext, JunctionType
22
- from typing import List, Tuple, Optional, Dict
23
- import torch
24
- import numpy as np
25
- import cv2
26
  import os
27
  import logging
 
28
 
 
 
 
 
 
29
  logger = logging.getLogger(__name__)
30
 
31
- class DiagramDetectionPipeline:
32
- """
33
- Pipeline that runs multiple detectors (line, point, junction, etc.) on an image,
34
- and keeps a shared DetectionContext in memory.
35
- """
36
-
37
- def __init__(self,
38
- tag_detector: Optional[BaseDetector],
39
- symbol_detector: Optional[BaseDetector],
40
- line_detector: Optional[BaseDetector],
41
- point_detector: Optional[BaseDetector],
42
- junction_detector: Optional[BaseDetector],
43
- storage: StorageInterface,
44
- debug_handler: Optional[DebugHandler] = None,
45
- transformer: Optional[CoordinateTransformer] = None):
46
- """
47
- You can pass None for detectors you don't need.
48
- """
49
- # super().__init__(storage=storage, debug_handler=debug_handler)
50
- self.storage = storage
51
- self.debug_handler = debug_handler
52
- self.tag_detector = tag_detector
53
- self.symbol_detector = symbol_detector
54
- self.line_detector = line_detector
55
- self.point_detector = point_detector
56
- self.junction_detector = junction_detector
57
- self.transformer = transformer or CoordinateTransformer()
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def _load_image(self, image_path: str) -> np.ndarray:
60
  """Load image with validation."""
61
  image_data = self.storage.load_file(image_path)
 
1
+ # Standard library imports first
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import os
3
  import logging
4
+ from typing import List, Dict, Optional, Any
5
 
6
+ # Configure logging before any other imports
7
+ logging.basicConfig(
8
+ level=logging.INFO,
9
+ format='%(asctime)s - %(levelname)s - %(message)s'
10
+ )
11
  logger = logging.getLogger(__name__)
12
 
13
+ # Third-party imports
14
+ import cv2
15
+ import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ # Local imports
18
+ from base import BaseDetectionPipeline
19
+ from config import (
20
+ LineConfig, ImageConfig, PointConfig, JunctionConfig,
21
+ SymbolConfig, TagConfig
22
+ )
23
+ from utils import DebugHandler
24
+ from storage import StorageInterface
25
+
26
+ # Import detectors after logging is configured
27
+ from detectors import (
28
+ LineDetector, PointDetector, JunctionDetector,
29
+ SymbolDetector, TagDetector
30
+ )
31
+
32
+ class DiagramDetectionPipeline(BaseDetectionPipeline):
33
+ """Main pipeline for processing P&ID diagrams"""
34
+
35
+ def __init__(
36
+ self,
37
+ storage: StorageInterface,
38
+ debug_handler: Optional[DebugHandler] = None
39
+ ):
40
+ super().__init__(storage, debug_handler)
41
+ # Initialize detectors when needed
42
+ self._line_detector = None
43
+ self._point_detector = None
44
+ self._junction_detector = None
45
+ self._symbol_detector = None
46
+ self._tag_detector = None
47
+
48
  def _load_image(self, image_path: str) -> np.ndarray:
49
  """Load image with validation."""
50
  image_data = self.storage.load_file(image_path)