AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: AI tagging aborts entire batch when encountering a corrupt/unreadable image

未关闭 适合新手
#1,496 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Python
星标
284
派生
680
平均合并
7 天 5 小时
30 天内合并 PR
4

描述

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

During the AI tagging pipeline (`image_util_classify_and_face_detect_images`), the `ObjectClassifier` safely returns `None` if `cv2.imread` fails to read an image (e.g., due to file corruption or unsupported format). However, the calling code assumes a list is always returned and immediately calls `len(classes) > 0`.

Because there is no try/except block around the loop body, this throws a `TypeError: object of type 'NoneType' has no len()` and permanently crashes the tagging process for the current folder. All subsequent valid images in the queue are skipped and left untagged.

## #Steps to Reproduce
1. Start PictoPy and ensure AI Tagging is enabled.
2. Add a folder containing multiple images, where at least one image is corrupted or is a 0-byte invalid file.
3. Observe that the indexing/tagging process stops abruptly at the corrupt image.
4. Check the backend logs to see a `TypeError` traceback originating from `if len(classes) > 0:` in `images.py`.
5. Observe that the remaining valid images in the folder are never AI-tagged.

### Expected Behavior
A corrupt image should be logged as a failure, skipped, and the AI tagging process should continue seamlessly for the remaining images in the folder.

### Actual Behavior
The entire background process aborts, leaving valid photos untagged.

### Code Pointers
- **Model Layer:** `backend/app/models/ObjectClassifier.py` (lines 17-21) returns `None` when `img is None`.
- **Calling Layer:** `backend/app/utils/images.py` (around line 170) does not check for `None` before checking `len()`.

### Suggested Fix
Update the check in `backend/app/utils/images.py` to handle the `None` case safely and wrap the loop body in a `try/except` block to prevent a single image failure from bubbling up and crashing the entire batch:
```python
if classes is not None and len(classes) > 0:
# Insert class-image pairs
```

I have isolated the root cause for this issue and would love to be assigned to submit a PR for it!

### Record

- [x] I agree to follow this project's Code of Conduct

贡献指南

打开贡献指南

调研方向

Start in backend/app/utils/images.py around line 170 and compare its handling of the None returned by backend/app/models/ObjectClassifier.py lines 17-21. Reproduce with a folder containing a corrupt or 0-byte image plus valid images, then verify the failure is logged and skipped while later valid images are AI-tagged without a TypeError.

由索引模型根据 Issue 内容生成。

评估

技术栈
opencv, python
领域
computer-vision, desktop
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
活跃
描述清晰度
描述清楚
新手友好度
88/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。