AOSSIE-Org / AOSSIE-Org/PictoPy

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

オープン 初心者向け
#1,496 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
284
フォーク
680
平均マージ
7日 5時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。