msIntui commited on
Commit
3f1e63e
·
1 Parent(s): b76ce91

Fix import order and logging initialization

Browse files
Files changed (2) hide show
  1. detectors.py +27 -11
  2. line_detectors.py +16 -8
detectors.py CHANGED
@@ -1,26 +1,42 @@
 
1
  import os
2
  import math
3
- import torch
4
- import cv2
5
- import numpy as np
6
- from typing import List, Optional, Tuple, Dict, Any
7
- from dataclasses import replace
8
- from math import sqrt
9
  import json
10
  import uuid
11
- from pathlib import Path
12
- from abc import ABC, abstractmethod
13
  import logging
14
- from PIL import Image
15
- import matplotlib.pyplot as plt
 
 
 
16
 
17
- # Configure logging first, before any other imports
18
  logging.basicConfig(
19
  level=logging.INFO,
20
  format='%(asctime)s - %(levelname)s - %(message)s'
21
  )
22
  logger = logging.getLogger(__name__)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # Base imports that shouldn't fail
25
  from storage import StorageInterface
26
  from base import BaseDetector
 
1
+ # Standard library imports first
2
  import os
3
  import math
 
 
 
 
 
 
4
  import json
5
  import uuid
 
 
6
  import logging
7
+ from abc import ABC, abstractmethod
8
+ from dataclasses import replace
9
+ from math import sqrt
10
+ from pathlib import Path
11
+ from typing import List, Optional, Tuple, Dict, Any
12
 
13
+ # Configure logging before any other imports
14
  logging.basicConfig(
15
  level=logging.INFO,
16
  format='%(asctime)s - %(levelname)s - %(message)s'
17
  )
18
  logger = logging.getLogger(__name__)
19
 
20
+ # Third-party imports
21
+ import cv2
22
+ import numpy as np
23
+ import torch
24
+ from PIL import Image
25
+ import matplotlib.pyplot as plt
26
+ from skimage.morphology import skeletonize
27
+ from skimage.measure import label
28
+ from ultralytics import YOLO
29
+
30
+ # Local imports
31
+ from storage import StorageInterface
32
+ from base import BaseDetector
33
+ from config import SymbolConfig, TagConfig, LineConfig, PointConfig, JunctionConfig
34
+ from line_detectors import OpenCVLineDetector, DeepLSDDetector, DEEPLSD_AVAILABLE
35
+ from detection_schema import (
36
+ BBox, Coordinates, Point, Line, Symbol, Tag,
37
+ SymbolType, LineStyle, ConnectionType, JunctionType, Junction
38
+ )
39
+
40
  # Base imports that shouldn't fail
41
  from storage import StorageInterface
42
  from base import BaseDetector
line_detectors.py CHANGED
@@ -1,10 +1,15 @@
 
1
  import logging
2
- import cv2
3
- import numpy as np
4
  from typing import Dict, Optional
5
 
 
 
6
  logger = logging.getLogger(__name__)
7
 
 
 
 
 
8
  class BaseLineDetector:
9
  """Base class for line detection methods"""
10
  def detect(self, image: np.ndarray) -> Dict:
@@ -34,18 +39,21 @@ class OpenCVLineDetector(BaseLineDetector):
34
 
35
  return {'detections': detections}
36
 
37
- # Try to import DeepLSD, but don't fail if not available
 
 
 
38
  try:
39
  from deeplsd.models.deeplsd_inference import DeepLSD
 
40
  class DeepLSDDetector(BaseLineDetector):
41
  def __init__(self, model_path: Optional[str] = None):
42
  self.model = DeepLSD(model_path) if model_path else None
43
 
44
  def detect(self, image: np.ndarray) -> Dict:
45
- # DeepLSD implementation
46
- return {'detections': []}
47
  DEEPLSD_AVAILABLE = True
 
48
  except ImportError as e:
49
- logger.warning(f"DeepLSD not available: {e}")
50
- DEEPLSD_AVAILABLE = False
51
- DeepLSDDetector = None
 
1
+ # Standard library imports
2
  import logging
 
 
3
  from typing import Dict, Optional
4
 
5
+ # Configure logging
6
+ logging.basicConfig(level=logging.INFO)
7
  logger = logging.getLogger(__name__)
8
 
9
+ # Third-party imports
10
+ import cv2
11
+ import numpy as np
12
+
13
  class BaseLineDetector:
14
  """Base class for line detection methods"""
15
  def detect(self, image: np.ndarray) -> Dict:
 
39
 
40
  return {'detections': detections}
41
 
42
+ # Try to import DeepLSD in a separate try-except block
43
+ DEEPLSD_AVAILABLE = False
44
+ DeepLSDDetector = None
45
+
46
  try:
47
  from deeplsd.models.deeplsd_inference import DeepLSD
48
+
49
  class DeepLSDDetector(BaseLineDetector):
50
  def __init__(self, model_path: Optional[str] = None):
51
  self.model = DeepLSD(model_path) if model_path else None
52
 
53
  def detect(self, image: np.ndarray) -> Dict:
54
+ return {'detections': []} # Placeholder implementation
55
+
56
  DEEPLSD_AVAILABLE = True
57
+
58
  except ImportError as e:
59
+ logger.warning(f"DeepLSD not available: {e}")