Skip to content

Feat: Fix Model Initialization Crash Risk #1212

@Kanika0306

Description

@Kanika0306

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

  • YOLO.py
  • FaceNet.py

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

  • I agree to follow this project's Code of Conduct
  • I want to work on this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions