matrice-analytics 0.1.39__py3-none-any.whl → 0.1.40__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of matrice-analytics might be problematic. Click here for more details.

@@ -31,94 +31,31 @@ import numpy as np
31
31
  #import torch
32
32
  import re
33
33
  from matrice_analytics.post_processing.core.config import BaseConfig, AlertConfig, ZoneConfig
34
- # Auto-install and import required dependencies for age/gender detection
35
- def try_import_age_gender_deps():
36
- """Try to import onnxruntime and PIL, auto-install if missing or fix NumPy issues."""
37
- try:
38
- import onnxruntime as ort
39
- from PIL import Image
40
- print("✓ Age/Gender dependencies imported successfully (onnxruntime, PIL)")
41
- return ort, Image
42
- except ImportError as e:
43
- error_msg = str(e)
44
- print(f"⚠ Import failed: {e}")
45
-
46
- # Check if it's a NumPy version mismatch issue
47
- if "NumPy" in error_msg and ("1.x" in error_msg or "2." in error_msg):
48
- print("→ DETECTED: NumPy version mismatch issue!")
49
- print("→ onnxruntime was compiled with NumPy 1.x but NumPy 2.x is installed")
50
- print("→ Attempting to downgrade NumPy to version <2...")
51
-
52
- import subprocess
53
- import sys
54
- try:
55
- print(" Downgrading numpy...")
56
- result = subprocess.run(
57
- [sys.executable, "-m", "pip", "install", "numpy<2", "--force-reinstall", "--no-warn-script-location"],
58
- capture_output=True,
59
- text=True,
60
- timeout=300
61
- )
62
- if result.returncode == 0:
63
- print(" ✓ NumPy downgraded successfully")
64
- print("→ Retrying onnxruntime import...")
65
- import onnxruntime as ort
66
- from PIL import Image
67
- print("✓ Dependencies imported after NumPy downgrade!")
68
- return ort, Image
69
- else:
70
- print(f" ✗ NumPy downgrade failed: {result.stderr}")
71
- return None, None
72
- except Exception as numpy_fix_err:
73
- print(f"✗ Failed to fix NumPy issue: {numpy_fix_err}")
74
- return None, None
75
-
76
- # Not a NumPy issue, try regular installation
77
- print("→ Attempting auto-installation of missing packages...")
78
- packages = []
79
- try:
80
- import onnxruntime
81
- except ImportError:
82
- packages.append("onnxruntime-gpu")
83
-
84
- try:
85
- from PIL import Image
86
- except ImportError:
87
- packages.append("pillow")
88
-
89
- if packages:
90
- print(f"→ Installing: {', '.join(packages)}")
91
- import subprocess
92
- import sys
93
- try:
94
- for pkg in packages:
95
- print(f" Installing {pkg}...")
96
- result = subprocess.run(
97
- [sys.executable, "-m", "pip", "install", pkg, "--no-warn-script-location"],
98
- capture_output=True,
99
- text=True,
100
- timeout=300
101
- )
102
- if result.returncode == 0:
103
- print(f" ✓ {pkg} installed")
104
- else:
105
- print(f" ✗ Failed: {result.stderr}")
106
-
107
- # Retry import
108
- print("→ Retrying imports...")
109
- import onnxruntime as ort
110
- from PIL import Image
111
- print("✓ Dependencies imported after auto-installation!")
112
- return ort, Image
113
- except Exception as install_err:
114
- print(f"✗ Installation failed: {install_err}")
115
- return None, None
116
- return None, None
117
- except Exception as e:
118
- print(f"✗ Unexpected error: {e}")
119
- return None, None
120
34
 
121
- ort, Image = try_import_age_gender_deps()
35
+ # Try to import optional age/gender dependencies (fail gracefully if missing)
36
+ ort = None
37
+ Image = None
38
+
39
+ try:
40
+ import onnxruntime as ort
41
+ from PIL import Image
42
+ print("✓ Age/Gender dependencies available (onnxruntime, PIL)")
43
+ except ImportError as e:
44
+ error_msg = str(e)
45
+ print(f"⚠ Age/Gender dependencies not available: {e}")
46
+
47
+ # Check if it's a NumPy version mismatch issue and provide helpful message
48
+ if "NumPy" in error_msg and ("1.x" in error_msg or "2." in error_msg):
49
+ print("→ DETECTED: NumPy version mismatch!")
50
+ print(" onnxruntime was compiled with NumPy 1.x but NumPy 2.x is installed")
51
+ print(" To fix manually: pip install 'numpy<2' --force-reinstall")
52
+ else:
53
+ print(" To enable manually: pip install onnxruntime-gpu pillow")
54
+
55
+ print("→ Age/Gender detection will be disabled")
56
+ except Exception as e:
57
+ print(f"⚠ Error importing Age/Gender dependencies: {e}")
58
+ print("→ Age/Gender detection will be disabled")
122
59
 
123
60
 
124
61
  def apply_category_mapping(results: Any, index_to_category: Dict[str, str]) -> Any:
@@ -29,89 +29,103 @@ import cv2
29
29
  import io
30
30
  import threading
31
31
 
32
- # Auto-install and import required dependencies for CLIP color detection
33
- def try_import_with_auto_install():
32
+ # Try to import optional CLIP dependencies (fail gracefully if missing)
33
+ # These will be None if not available, and auto-install will be attempted on first use
34
+ ort = None
35
+ Image = None
36
+ CLIPProcessor = None
37
+ ir_files = None
38
+ ir_as_file = None
39
+
40
+ try:
41
+ import onnxruntime as ort
42
+ from PIL import Image
43
+ from transformers import CLIPProcessor
44
+ from importlib.resources import files as ir_files, as_file as ir_as_file
45
+ print("✓ CLIP dependencies available (onnxruntime, PIL, transformers)")
46
+ except ImportError as e:
47
+ print(f"⚠ CLIP dependencies not available at import time: {e}")
48
+ print("→ Will attempt auto-installation when color detection is first used")
49
+ except Exception as e:
50
+ print(f"⚠ Error importing CLIP dependencies: {e}")
51
+ print("→ Color detection may be disabled")
52
+
53
+ def try_install_clip_dependencies():
34
54
  """
35
- Try to import required dependencies, auto-install if missing, then try again.
36
- Returns tuple of (ort, Image, CLIPProcessor, ir_files, ir_as_file)
55
+ Attempt to install missing CLIP dependencies.
56
+ Only called when ClipProcessor is actually instantiated (lazy installation).
57
+ Returns True if successful, False otherwise.
37
58
  """
38
- # First attempt: try to import
59
+ global ort, Image, CLIPProcessor, ir_files, ir_as_file
60
+
61
+ print("→ Color detection is being used but dependencies are missing")
62
+ print("→ Attempting auto-installation of missing packages...")
63
+
64
+ packages_to_install = []
65
+
66
+ # Check which packages are missing
39
67
  try:
40
- import onnxruntime as ort
41
- from PIL import Image
42
- from transformers import CLIPProcessor
43
- from importlib.resources import files as ir_files, as_file as ir_as_file
44
- print("✓ CLIP dependencies imported successfully (onnxruntime, PIL, transformers)")
45
- return ort, Image, CLIPProcessor, ir_files, ir_as_file
46
- except ImportError as e:
47
- print(f"⚠ Import failed on first attempt: {e}")
48
- print("→ Attempting auto-installation of missing packages...")
68
+ import onnxruntime
69
+ except ImportError:
70
+ packages_to_install.append("onnxruntime-gpu")
49
71
 
50
- # Try to install missing packages
51
- packages_to_install = []
72
+ try:
73
+ from PIL import Image as PILImage
74
+ except ImportError:
75
+ packages_to_install.append("pillow")
52
76
 
53
- # Check which specific packages are missing
54
- try:
55
- import onnxruntime
56
- except ImportError:
57
- packages_to_install.append("onnxruntime-gpu")
77
+ try:
78
+ from transformers import CLIPProcessor as CLIP
79
+ except ImportError:
80
+ packages_to_install.append("transformers")
58
81
 
59
- try:
60
- from PIL import Image
61
- except ImportError:
62
- packages_to_install.append("pillow")
82
+ if not packages_to_install:
83
+ print("→ All packages are available, retrying import...")
84
+ else:
85
+ print(f"→ Installing: {', '.join(packages_to_install)}")
63
86
 
87
+ import subprocess
64
88
  try:
65
- from transformers import CLIPProcessor
66
- except ImportError:
67
- packages_to_install.append("transformers")
89
+ for package in packages_to_install:
90
+ print(f" Installing {package}...")
91
+ result = subprocess.run(
92
+ [sys.executable, "-m", "pip", "install", package, "--no-warn-script-location"],
93
+ capture_output=True,
94
+ text=True,
95
+ timeout=300
96
+ )
97
+ if result.returncode == 0:
98
+ print(f" ✓ {package} installed successfully")
99
+ else:
100
+ print(f" ✗ Failed to install {package}: {result.stderr}")
101
+ return False
102
+ except Exception as install_error:
103
+ print(f"✗ Installation failed: {install_error}")
104
+ return False
68
105
 
69
- if packages_to_install:
70
- print(f"→ Installing: {', '.join(packages_to_install)}")
71
- try:
72
- # Use sys.executable to ensure we install to the correct Python environment
73
- for package in packages_to_install:
74
- print(f" Installing {package}...")
75
- result = subprocess.run(
76
- [sys.executable, "-m", "pip", "install", package, "--no-warn-script-location"],
77
- capture_output=True,
78
- text=True,
79
- timeout=300 # 5 minute timeout
80
- )
81
- if result.returncode == 0:
82
- print(f" ✓ {package} installed successfully")
83
- else:
84
- print(f" Failed to install {package}: {result.stderr}")
85
-
86
- # Second attempt: try to import after installation
87
- print(" Retrying imports after installation...")
88
- try:
89
- import onnxruntime as ort
90
- from PIL import Image
91
- from transformers import CLIPProcessor
92
- from importlib.resources import files as ir_files, as_file as ir_as_file
93
- print("✓ CLIP dependencies imported successfully after auto-installation!")
94
- return ort, Image, CLIPProcessor, ir_files, ir_as_file
95
- except ImportError as e2:
96
- print(f"✗ Import still failed after installation: {e2}")
97
- print("→ Color detection will be disabled")
98
- return None, None, None, None, None
99
-
100
- except subprocess.TimeoutExpired:
101
- print("✗ Installation timeout - packages took too long to install")
102
- return None, None, None, None, None
103
- except Exception as install_error:
104
- print(f"✗ Installation error: {install_error}")
105
- return None, None, None, None, None
106
- else:
107
- print("✗ Unable to determine which packages are missing")
108
- return None, None, None, None, None
106
+ # Retry imports after installation
107
+ try:
108
+ print("→ Retrying imports after installation...")
109
+ import onnxruntime as ort_module
110
+ from PIL import Image as PILImage
111
+ from transformers import CLIPProcessor as CLIPProc
112
+ from importlib.resources import files as ir_files_module, as_file as ir_as_file_module
113
+
114
+ # Update global variables
115
+ ort = ort_module
116
+ Image = PILImage
117
+ CLIPProcessor = CLIPProc
118
+ ir_files = ir_files_module
119
+ ir_as_file = ir_as_file_module
120
+
121
+ print(" CLIP dependencies imported successfully after installation!")
122
+ return True
123
+ except ImportError as e:
124
+ print(f" Import still failed after installation: {e}")
125
+ return False
109
126
  except Exception as e:
110
- print(f"✗ Unexpected error during import: {e}")
111
- return None, None, None, None, None
112
-
113
- # Execute the auto-install import
114
- ort, Image, CLIPProcessor, ir_files, ir_as_file = try_import_with_auto_install()
127
+ print(f"✗ Unexpected error: {e}")
128
+ return False
115
129
 
116
130
  def load_model_from_checkpoint(checkpoint_url: str, providers: Optional[List] = None):
117
131
  """
@@ -186,16 +200,22 @@ class ClipProcessor:
186
200
  processor_dir: Optional[str] = None,
187
201
  providers: Optional[List[str]] = None):
188
202
 
189
- # Check if required dependencies are available
203
+ # Check if required dependencies are available, try auto-install if not
190
204
  if ort is None or CLIPProcessor is None or Image is None:
191
- raise RuntimeError(
192
- "Required dependencies for ClipProcessor are not available.\n"
193
- "Missing: " +
194
- (("onnxruntime " if ort is None else "") +
195
- ("transformers(CLIPProcessor) " if CLIPProcessor is None else "") +
196
- ("PIL(Image) " if Image is None else "")).strip() + "\n"
197
- "Please install: pip install transformers onnxruntime-gpu pillow"
198
- )
205
+ print("⚠ Color detection dependencies missing, attempting auto-installation...")
206
+
207
+ # Try to auto-install missing dependencies (lazy installation)
208
+ if not try_install_clip_dependencies():
209
+ raise RuntimeError(
210
+ "Required dependencies for ClipProcessor are not available.\n"
211
+ "Auto-installation failed. Missing: " +
212
+ (("onnxruntime " if ort is None else "") +
213
+ ("transformers(CLIPProcessor) " if CLIPProcessor is None else "") +
214
+ ("PIL(Image) " if Image is None else "")).strip() + "\n"
215
+ "Please install manually: pip install transformers onnxruntime-gpu pillow"
216
+ )
217
+
218
+ print("✓ Auto-installation successful, continuing with ClipProcessor initialization")
199
219
 
200
220
  self.color_category: List[str] = ["black", "white", "yellow", "gray", "red", "blue", "light blue",
201
221
  "green", "brown"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matrice_analytics
3
- Version: 0.1.39
3
+ Version: 0.1.40
4
4
  Summary: Common server utilities for Matrice.ai services
5
5
  Author-email: "Matrice.ai" <dipendra@matrice.ai>
6
6
  License-Expression: MIT
@@ -87,7 +87,7 @@ matrice_analytics/post_processing/usecases/__init__.py,sha256=tsu51e2q2gbr5UcALe
87
87
  matrice_analytics/post_processing/usecases/abandoned_object_detection.py,sha256=zVrqlvgsjc5F2JHd-Zav6d-poVIpTJBpPKZ3CC71lQk,40332
88
88
  matrice_analytics/post_processing/usecases/advanced_customer_service.py,sha256=ELt5euxr6P4X2s8-YGngmj27QscOHefjOsx3774sNFk,75914
89
89
  matrice_analytics/post_processing/usecases/age_detection.py,sha256=yn1LXOgbnOWSMDnsCds6-uN6W-I1Hy4_-AMrjbT5PtY,41318
90
- matrice_analytics/post_processing/usecases/age_gender_detection.py,sha256=liWcwP4-rC97iVH2wzeDTdCPud-eZ5ZKg4odHLIrI4M,55131
90
+ matrice_analytics/post_processing/usecases/age_gender_detection.py,sha256=ok8uCG8pHKqouTSOQyUANou29k6OOohxnhFsTwayOL0,52533
91
91
  matrice_analytics/post_processing/usecases/anti_spoofing_detection.py,sha256=XdtDdXGzZMLQdWcoOoiE5t4LPYHhgOtJ7tZCNlq1A2E,31329
92
92
  matrice_analytics/post_processing/usecases/assembly_line_detection.py,sha256=I_oeuec84KJnGMg_A8Wgs9U6h_IiopkDz9FbM1JG110,40410
93
93
  matrice_analytics/post_processing/usecases/banana_defect_detection.py,sha256=uKvB550Xve3iWfdWeOU3VhgORxD-M_UzsQDQKkYcFBc,30338
@@ -166,7 +166,7 @@ matrice_analytics/post_processing/usecases/weld_defect_detection.py,sha256=b0dAJ
166
166
  matrice_analytics/post_processing/usecases/wildlife_monitoring.py,sha256=TMVHJ5GLezmqG7DywmqbLggqNXgpsb63MD7IR6kvDkk,43446
167
167
  matrice_analytics/post_processing/usecases/windmill_maintenance.py,sha256=G1eqo3Z-HYmGJ6oeZYrpZwhpvqQ9Lc_T-6S7BLBXHeA,40498
168
168
  matrice_analytics/post_processing/usecases/wound_segmentation.py,sha256=ehNX6VuWMB3xAnCySO3ra3Tf_5FUNg5LCSdq_91h374,38342
169
- matrice_analytics/post_processing/usecases/color/clip.py,sha256=ZUqj0s0KFcU6kZ21hpiQWO3CRqn8s5EZ3IhWTskHbS8,21322
169
+ matrice_analytics/post_processing/usecases/color/clip.py,sha256=12ir0RkJCb4FJErn_e_9UbjtbBki5PMH2hWJLzyV75Q,21471
170
170
  matrice_analytics/post_processing/usecases/color/color_map_utils.py,sha256=SP-AEVcjLmL8rxblu-ixqUJC2fqlcr7ab4hWo4Fcr_k,2677
171
171
  matrice_analytics/post_processing/usecases/color/color_mapper.py,sha256=nKPc28mJLlrl2HPua5EUUMweRRSI6WrrUBkeitTm7ms,17459
172
172
  matrice_analytics/post_processing/usecases/color/clip_processor/merges.txt,sha256=n9aR98gDkhDg_O0VhlRmxlgg0JtjmIsBdL_iXeKZBRo,524619
@@ -188,8 +188,8 @@ matrice_analytics/post_processing/utils/format_utils.py,sha256=UTF7A5h9j0_S12xH9
188
188
  matrice_analytics/post_processing/utils/geometry_utils.py,sha256=BWfdM6RsdJTTLR1GqkWfdwpjMEjTCJyuBxA4zVGKdfk,9623
189
189
  matrice_analytics/post_processing/utils/smoothing_utils.py,sha256=78U-yucAcjUiZ0NIAc9NOUSIT0PWP1cqyIPA_Fdrjp0,14699
190
190
  matrice_analytics/post_processing/utils/tracking_utils.py,sha256=rWxuotnJ3VLMHIBOud2KLcu4yZfDp7hVPWUtNAq_2xw,8288
191
- matrice_analytics-0.1.39.dist-info/licenses/LICENSE.txt,sha256=_uQUZpgO0mRYL5-fPoEvLSbNnLPv6OmbeEDCHXhK6Qc,1066
192
- matrice_analytics-0.1.39.dist-info/METADATA,sha256=3btcsrjFcTzAkncEjVaPi4hUNRHDBFe34x4uJ6Mf1Kg,14378
193
- matrice_analytics-0.1.39.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
194
- matrice_analytics-0.1.39.dist-info/top_level.txt,sha256=STAPEU-e-rWTerXaspdi76T_eVRSrEfFpURSP7_Dt8E,18
195
- matrice_analytics-0.1.39.dist-info/RECORD,,
191
+ matrice_analytics-0.1.40.dist-info/licenses/LICENSE.txt,sha256=_uQUZpgO0mRYL5-fPoEvLSbNnLPv6OmbeEDCHXhK6Qc,1066
192
+ matrice_analytics-0.1.40.dist-info/METADATA,sha256=tROotN2KHqbTIpf18BknZQ8Z4zO8VHNMcf7f1q4svas,14378
193
+ matrice_analytics-0.1.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
194
+ matrice_analytics-0.1.40.dist-info/top_level.txt,sha256=STAPEU-e-rWTerXaspdi76T_eVRSrEfFpURSP7_Dt8E,18
195
+ matrice_analytics-0.1.40.dist-info/RECORD,,