scorevision: push artifact
Browse files
miner.py
CHANGED
|
@@ -45,11 +45,27 @@ class Miner:
|
|
| 45 |
if not self.onnx_path.exists():
|
| 46 |
raise FileNotFoundError(f'Model not found at {self.onnx_path}')
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
providers: list = []
|
| 49 |
try:
|
| 50 |
ort.preload_dlls()
|
| 51 |
-
except Exception:
|
| 52 |
-
|
| 53 |
available = ort.get_available_providers()
|
| 54 |
if 'CUDAExecutionProvider' in available:
|
| 55 |
providers.append(('CUDAExecutionProvider', {'device_id': 0}))
|
|
@@ -61,10 +77,13 @@ class Miner:
|
|
| 61 |
inp = self.session.get_inputs()[0]
|
| 62 |
self.input_shape = inp.shape
|
| 63 |
self.input_dtype = np.float16 if inp.type == 'tensor(float16)' else np.float32
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def __repr__(self) -> str:
|
| 67 |
-
return f'PetrolMiner(yolo11s-onnx-fp16-nms, tta={self.USE_TTA}, conf={self.CONF_THRES})'
|
| 68 |
|
| 69 |
@staticmethod
|
| 70 |
def _letterbox(img, new_size=1280, color=(114, 114, 114)):
|
|
|
|
| 45 |
if not self.onnx_path.exists():
|
| 46 |
raise FileNotFoundError(f'Model not found at {self.onnx_path}')
|
| 47 |
|
| 48 |
+
# Help ORT find CUDA libs shipped with nvidia-*-cu12 packages (pytorch/onnxruntime).
|
| 49 |
+
import os as _os
|
| 50 |
+
import site as _site
|
| 51 |
+
import glob as _glob
|
| 52 |
+
cuda_lib_dirs: list[str] = []
|
| 53 |
+
for sp in _site.getsitepackages() + [_site.getusersitepackages()]:
|
| 54 |
+
for sub in ('nvidia/cuda_runtime/lib', 'nvidia/cublas/lib', 'nvidia/cudnn/lib',
|
| 55 |
+
'nvidia/cufft/lib', 'nvidia/cuda_nvrtc/lib', 'nvidia/curand/lib',
|
| 56 |
+
'nvidia/cusparse/lib', 'nvidia/cusolver/lib', 'nvidia/nvjitlink/lib'):
|
| 57 |
+
p = f'{sp}/{sub}'
|
| 58 |
+
if _glob.glob(f'{p}/*.so*'):
|
| 59 |
+
cuda_lib_dirs.append(p)
|
| 60 |
+
if cuda_lib_dirs:
|
| 61 |
+
existing = _os.environ.get('LD_LIBRARY_PATH', '')
|
| 62 |
+
_os.environ['LD_LIBRARY_PATH'] = ':'.join(cuda_lib_dirs + ([existing] if existing else []))
|
| 63 |
+
|
| 64 |
providers: list = []
|
| 65 |
try:
|
| 66 |
ort.preload_dlls()
|
| 67 |
+
except Exception as _pe:
|
| 68 |
+
print(f'[Miner] preload_dlls failed: {_pe}')
|
| 69 |
available = ort.get_available_providers()
|
| 70 |
if 'CUDAExecutionProvider' in available:
|
| 71 |
providers.append(('CUDAExecutionProvider', {'device_id': 0}))
|
|
|
|
| 77 |
inp = self.session.get_inputs()[0]
|
| 78 |
self.input_shape = inp.shape
|
| 79 |
self.input_dtype = np.float16 if inp.type == 'tensor(float16)' else np.float32
|
| 80 |
+
self.active_providers = self.session.get_providers()
|
| 81 |
+
print(f'[Miner] Loaded {self.onnx_path.name} | providers={self.active_providers} | dtype={self.input_dtype}')
|
| 82 |
+
print(f'[Miner] cuda_lib_dirs discovered: {cuda_lib_dirs[:3]}')
|
| 83 |
+
print(f'[Miner] ort.get_available_providers() = {available}')
|
| 84 |
|
| 85 |
def __repr__(self) -> str:
|
| 86 |
+
return f'PetrolMiner(yolo11s-onnx-fp16-nms, tta={self.USE_TTA}, conf={self.CONF_THRES}, providers={getattr(self, "active_providers", "?")})'
|
| 87 |
|
| 88 |
@staticmethod
|
| 89 |
def _letterbox(img, new_size=1280, color=(114, 114, 114)):
|