matrice-analytics 0.1.38__py3-none-any.whl → 0.1.39__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,11 +31,94 @@ 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
- try:
35
- from PIL import Image
36
- import onnxruntime as ort
37
- except:
38
- print("Unable to import onnxruntime")
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
+
121
+ ort, Image = try_import_age_gender_deps()
39
122
 
40
123
 
41
124
  def apply_category_mapping(results: Any, index_to_category: Dict[str, str]) -> Any:
@@ -89,9 +172,16 @@ def load_model_from_checkpoint(checkpoint_path,local_path):
89
172
  """
90
173
  Load a model from checkpoint URL
91
174
  """
175
+ if ort is None:
176
+ raise RuntimeError(
177
+ "onnxruntime is not available. Cannot load age/gender detection models.\n"
178
+ "Please install: pip install onnxruntime-gpu\n"
179
+ "Or downgrade numpy: pip install 'numpy<2'"
180
+ )
181
+
92
182
  try:
93
183
  print(f"Loading model from checkpoint: {checkpoint_path}")
94
-
184
+
95
185
  # Check if checkpoint is a URL
96
186
  if checkpoint_path.startswith(('http://', 'https://')):
97
187
  # Download checkpoint from URL
@@ -153,10 +243,25 @@ class AgeGenderConfig(BaseConfig):
153
243
 
154
244
  def __post_init__(self):
155
245
  if self.gender_url and self.age_url:
156
- self.age_url = load_model_from_checkpoint(self.age_url, "age_detection_prod_model.onnx")
157
- self.gender_url = load_model_from_checkpoint(self.gender_url, "gender_detection_prod_model.onnx")
246
+ try:
247
+ self.age_url = load_model_from_checkpoint(self.age_url, "age_detection_prod_model.onnx")
248
+ self.gender_url = load_model_from_checkpoint(self.gender_url, "gender_detection_prod_model.onnx")
249
+ print("✓ Age and Gender models loaded successfully")
250
+ except RuntimeError as e:
251
+ print(f"✗ Failed to load Age/Gender models: {e}")
252
+ print("→ Age/Gender detection will be disabled")
253
+ self.age_url = None
254
+ self.gender_url = None
255
+ except Exception as e:
256
+ print(f"✗ Unexpected error loading Age/Gender models: {e}")
257
+ import traceback
258
+ traceback.print_exc()
259
+ self.age_url = None
260
+ self.gender_url = None
158
261
  else:
159
- raise ValueError("Age and Gender model URL must be passed!")
262
+ print("Age and Gender model URLs not provided - detection will be disabled")
263
+ self.age_url = None
264
+ self.gender_url = None
160
265
 
161
266
 
162
267
  class AgeGenderUseCase(BaseProcessor):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matrice_analytics
3
- Version: 0.1.38
3
+ Version: 0.1.39
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=JSmQOSXdERZ6lOa28OrYBMEWa6Ey6VGv_mLjrRHIgts,50703
90
+ matrice_analytics/post_processing/usecases/age_gender_detection.py,sha256=liWcwP4-rC97iVH2wzeDTdCPud-eZ5ZKg4odHLIrI4M,55131
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
@@ -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.38.dist-info/licenses/LICENSE.txt,sha256=_uQUZpgO0mRYL5-fPoEvLSbNnLPv6OmbeEDCHXhK6Qc,1066
192
- matrice_analytics-0.1.38.dist-info/METADATA,sha256=486XlgiBZP14Sdp7HlHG1T4B-vPjNYRhYvMC4m0JPNs,14378
193
- matrice_analytics-0.1.38.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
194
- matrice_analytics-0.1.38.dist-info/top_level.txt,sha256=STAPEU-e-rWTerXaspdi76T_eVRSrEfFpURSP7_Dt8E,18
195
- matrice_analytics-0.1.38.dist-info/RECORD,,
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,,