Describe the feature
Model Initialization Error Handling
Both the YOLO and FaceNet classes initialize the model session without error handling.
If the model file is missing or hardware acceleration (CUDA) fails, the program crashes.
Files
YOLO.py (Model)
FaceNet.py (Model)
Issue
onnxruntime.InferenceSession is initialized without a try...except block.
Fix
Wrap the initialization in a try...except block and:
- provide a fallback to
CPUExecutionProvider, or
- log a clear error message.
Add ScreenShots
Affected Files
Description
Both model classes initialize an ONNX Runtime session directly using onnxruntime.InferenceSession(...) without any exception handling. Since this constructor performs model loading and execution provider initialization, any failure during this process can crash the backend server.
Code Locations
1. YOLO Model Initialization (YOLO.py)
23: self.session = onnxruntime.InferenceSession(
24: self.model_path, providers=ONNX_util_get_execution_providers()
25: )
2. FaceNet Model Initialization (FaceNet.py)
14: self.session = onnxruntime.InferenceSession(
15: model_path, providers=ONNX_util_get_execution_providers()
16: )
Why This Is a Risk
The onnxruntime.InferenceSession constructor is a blocking operation that attempts to:
- Load the
.onnx model file
- Initialize execution providers (e.g., CUDA, CPU)
- Allocate required runtime resources
If anything fails during this step, an exception is raised. Common causes include:
- Missing or corrupted
.onnx model file
- Incorrect model path
- CUDA or GPU driver incompatibility
- Failure to initialize execution providers
- Permission or filesystem issues
Since these calls are not wrapped in a try/except block, the exception propagates upward and can crash the entire backend service during startup.
Impact
- Backend server may fail to start
- No graceful error reporting
- No fallback to CPU execution provider
- Reduced system reliability in production
Record
Describe the feature
Model Initialization Error Handling
Both the YOLO and FaceNet classes initialize the model session without error handling.
If the model file is missing or hardware acceleration (CUDA) fails, the program crashes.
Files
YOLO.py(Model)FaceNet.py(Model)Issue
onnxruntime.InferenceSessionis initialized without atry...exceptblock.Fix
Wrap the initialization in a
try...exceptblock and:CPUExecutionProvider, orAdd ScreenShots
Affected Files
YOLO.pyFaceNet.pyDescription
Both model classes initialize an ONNX Runtime session directly using
onnxruntime.InferenceSession(...)without any exception handling. Since this constructor performs model loading and execution provider initialization, any failure during this process can crash the backend server.Code Locations
1. YOLO Model Initialization (
YOLO.py)2. FaceNet Model Initialization (
FaceNet.py)Why This Is a Risk
The
onnxruntime.InferenceSessionconstructor is a blocking operation that attempts to:.onnxmodel fileIf anything fails during this step, an exception is raised. Common causes include:
.onnxmodel fileSince these calls are not wrapped in a
try/exceptblock, the exception propagates upward and can crash the entire backend service during startup.Impact
Record