AOSSIE-Org / AOSSIE-Org/PictoPy

Feat: Fix Model Initialization Crash Risk

Offen
#1,212 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
283
Forks
679
Ø Merge
7 T. 2 Std.
Gemergte PRs (30 T.)
3

Beschreibung

### 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`)
```python
23: self.session = onnxruntime.InferenceSession(
24: self.model_path, providers=ONNX_util_get_execution_providers()
25: )
```

#### 2. FaceNet Model Initialization (`FaceNet.py`)
```python
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

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.