matrice-analytics 0.1.39__py3-none-any.whl → 0.1.41__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,184 @@ 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
39
- 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...")
59
+ print("→ Color detection is being used but dependencies are missing")
60
+ print("→ Attempting auto-installation of missing packages...")
49
61
 
50
- # Try to install missing packages
51
- packages_to_install = []
62
+ import platform
63
+ import subprocess
52
64
 
53
- # Check which specific packages are missing
54
- try:
55
- import onnxruntime
56
- except ImportError:
57
- packages_to_install.append("onnxruntime-gpu")
65
+ # Detect platform
66
+ machine = platform.machine().lower()
67
+ is_jetson = machine in ['aarch64', 'arm64'] or os.path.exists('/etc/nv_tegra_release')
68
+
69
+ if is_jetson:
70
+ print(f"→ Detected Jetson/ARM platform ({machine})")
71
+ else:
72
+ print(f"→ Detected x86_64 platform ({machine})")
58
73
 
74
+ packages_to_install = []
75
+
76
+ # Helper function to check if package is installed
77
+ def is_package_installed(package_name):
59
78
  try:
60
- from PIL import Image
61
- except ImportError:
79
+ result = subprocess.run(
80
+ [sys.executable, "-m", "pip", "show", package_name],
81
+ capture_output=True,
82
+ text=True,
83
+ timeout=10
84
+ )
85
+ return result.returncode == 0
86
+ except Exception:
87
+ return False
88
+
89
+ # Check which packages are missing
90
+ try:
91
+ import onnxruntime
92
+ print("→ onnxruntime imported successfully")
93
+ except ImportError as e:
94
+ # Check if onnxruntime is installed but import is failing
95
+ if is_package_installed("onnxruntime"):
96
+ print(f"→ onnxruntime is installed but import failed: {e}")
97
+ print("→ This may be due to NumPy version mismatch or CUDA library issues")
98
+ print("→ Skipping installation, will check other dependencies")
99
+ elif is_jetson and is_package_installed("onnxruntime-gpu"):
100
+ print("→ onnxruntime-gpu found on Jetson (this may not work on ARM)")
101
+ print("→ Attempting import with installed version")
102
+ else:
103
+ # Choose appropriate onnxruntime package based on platform
104
+ if is_jetson:
105
+ print("→ onnxruntime not installed on Jetson platform")
106
+ print("→ Note: Jetson usually has onnxruntime pre-installed via JetPack")
107
+ print("→ If you see this, check your JetPack installation")
108
+ # Try installing anyway
109
+ packages_to_install.append("onnxruntime")
110
+ else:
111
+ packages_to_install.append("onnxruntime-gpu")
112
+
113
+ try:
114
+ from PIL import Image as PILImage
115
+ print("→ PIL/Pillow imported successfully")
116
+ except ImportError:
117
+ if not is_package_installed("pillow") and not is_package_installed("PIL"):
62
118
  packages_to_install.append("pillow")
119
+ else:
120
+ print("→ pillow is installed but import failed")
63
121
 
64
- try:
65
- from transformers import CLIPProcessor
66
- except ImportError:
122
+ try:
123
+ from transformers import CLIPProcessor as CLIP
124
+ print("→ transformers imported successfully")
125
+ except ImportError:
126
+ if not is_package_installed("transformers"):
67
127
  packages_to_install.append("transformers")
68
-
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
128
  else:
107
- print(" Unable to determine which packages are missing")
108
- return None, None, None, None, None
129
+ print(" transformers is installed but import failed (may be incompatible with torch version)")
130
+
131
+ if not packages_to_install:
132
+ print("→ All packages are available, retrying import...")
133
+ else:
134
+ print(f"→ Installing: {', '.join(packages_to_install)}")
135
+
136
+ import subprocess
137
+ try:
138
+ for package in packages_to_install:
139
+ print(f" Installing {package}...")
140
+ result = subprocess.run(
141
+ [sys.executable, "-m", "pip", "install", package, "--no-warn-script-location"],
142
+ capture_output=True,
143
+ text=True,
144
+ timeout=300
145
+ )
146
+ if result.returncode == 0:
147
+ print(f" ✓ {package} installed successfully")
148
+ else:
149
+ print(f" ✗ Failed to install {package}: {result.stderr}")
150
+ return False
151
+ except Exception as install_error:
152
+ print(f"✗ Installation failed: {install_error}")
153
+ return False
154
+
155
+ # Retry imports after installation (or if packages were already installed)
156
+ print("→ Attempting to import dependencies...")
157
+
158
+ ort_module = None
159
+ PILImage = None
160
+ CLIPProc = None
161
+ ir_files_module = None
162
+ ir_as_file_module = None
163
+
164
+ import_errors = []
165
+
166
+ # Try importing each package individually
167
+ try:
168
+ import onnxruntime as ort_module
169
+ print(" ✓ onnxruntime imported")
170
+ except Exception as e:
171
+ import_errors.append(f"onnxruntime: {e}")
172
+ print(f" ✗ onnxruntime import failed: {e}")
173
+
174
+ try:
175
+ from PIL import Image as PILImage
176
+ print(" ✓ PIL imported")
177
+ except Exception as e:
178
+ import_errors.append(f"PIL: {e}")
179
+ print(f" ✗ PIL import failed: {e}")
180
+
181
+ try:
182
+ from transformers import CLIPProcessor as CLIPProc
183
+ print(" ✓ transformers imported")
184
+ except Exception as e:
185
+ import_errors.append(f"transformers: {e}")
186
+ print(f" ✗ transformers import failed: {e}")
187
+
188
+ try:
189
+ from importlib.resources import files as ir_files_module, as_file as ir_as_file_module
190
+ print(" ✓ importlib.resources imported")
109
191
  except Exception as e:
110
- print(f"✗ Unexpected error during import: {e}")
111
- return None, None, None, None, None
192
+ import_errors.append(f"importlib.resources: {e}")
193
+ print(f" ✗ importlib.resources import failed: {e}")
194
+
195
+ # Check if we have at least the critical dependencies
196
+ if ort_module is None or PILImage is None or CLIPProc is None:
197
+ print(f"✗ Critical dependencies missing after installation attempt")
198
+ print(f" Errors: {'; '.join(import_errors)}")
199
+ return False
200
+
201
+ # Update global variables with successfully imported modules
202
+ globals()['ort'] = ort_module
203
+ globals()['Image'] = PILImage
204
+ globals()['CLIPProcessor'] = CLIPProc
205
+ globals()['ir_files'] = ir_files_module
206
+ globals()['ir_as_file'] = ir_as_file_module
112
207
 
113
- # Execute the auto-install import
114
- ort, Image, CLIPProcessor, ir_files, ir_as_file = try_import_with_auto_install()
208
+ print("✓ CLIP dependencies imported successfully!")
209
+ return True
115
210
 
116
211
  def load_model_from_checkpoint(checkpoint_url: str, providers: Optional[List] = None):
117
212
  """
@@ -186,16 +281,22 @@ class ClipProcessor:
186
281
  processor_dir: Optional[str] = None,
187
282
  providers: Optional[List[str]] = None):
188
283
 
189
- # Check if required dependencies are available
284
+ # Check if required dependencies are available, try auto-install if not
190
285
  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
- )
286
+ print("⚠ Color detection dependencies missing, attempting auto-installation...")
287
+
288
+ # Try to auto-install missing dependencies (lazy installation)
289
+ if not try_install_clip_dependencies():
290
+ raise RuntimeError(
291
+ "Required dependencies for ClipProcessor are not available.\n"
292
+ "Auto-installation failed. Missing: " +
293
+ (("onnxruntime " if ort is None else "") +
294
+ ("transformers(CLIPProcessor) " if CLIPProcessor is None else "") +
295
+ ("PIL(Image) " if Image is None else "")).strip() + "\n"
296
+ "Please install manually: pip install transformers onnxruntime-gpu pillow"
297
+ )
298
+
299
+ print("✓ Auto-installation successful, continuing with ClipProcessor initialization")
199
300
 
200
301
  self.color_category: List[str] = ["black", "white", "yellow", "gray", "red", "blue", "light blue",
201
302
  "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.41
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=qtG1YUngpt-5Emx4vdX1Hv_X9U6Sa4BMCNRDYpuM_4g,24828
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.41.dist-info/licenses/LICENSE.txt,sha256=_uQUZpgO0mRYL5-fPoEvLSbNnLPv6OmbeEDCHXhK6Qc,1066
192
+ matrice_analytics-0.1.41.dist-info/METADATA,sha256=aGpFsA4ZZ5rNPFR2iqDy8JlA-gAhpAtjniELau5yH1I,14378
193
+ matrice_analytics-0.1.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
194
+ matrice_analytics-0.1.41.dist-info/top_level.txt,sha256=STAPEU-e-rWTerXaspdi76T_eVRSrEfFpURSP7_Dt8E,18
195
+ matrice_analytics-0.1.41.dist-info/RECORD,,