Skip to content

Object sensors: skip taught boxes whose image is missing on disk - #46

Closed
wzd8888 wants to merge 1 commit into
oleost:mainfrom
wzd8888:fix/taught-missing-image
Closed

wzd8888 wants to merge 1 commit into
oleost:mainfrom
wzd8888:fix/taught-missing-image

Conversation

@wzd8888

@wzd8888 wzd8888 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

What

An object sensor with taught boxes builds its taught index from the stored image of every taught box. _build_taught (visionstate/engine/teaching.py) collects every taught row, and _taught_vectors then opens each image. If the image for one box is gone — a partly restored data directory, a manual or external clean-up — imaging.load raises FileNotFoundError and the whole index build fails, so the sensor reports an error and stops matching any box.

This is the failure reported in #45: an object sensor raising [Errno 2] No such file or directory: '/media/visionstate/samples/3/…jpg'.

Change

_build_taught now drops the taught boxes whose image is missing on disk before embedding, logging which ids were skipped, and builds the index from the boxes that are still there.

This matches how the rest of the app already tolerates a missing image: imaging.load frees the file immediately because it "may be deleted meanwhile", and the import path skips a broken sample instead of failing the whole import.

The change is local: 6 lines in teaching.py, plus a regression test.

Test

tests/test_teach.py::test_a_taught_box_whose_image_is_gone_is_skipped (no models required): teaches two boxes, deletes one image, and asserts the index is still built from the remaining box. Before the change it fails with the reproduced FileNotFoundError; after it passes.

  • pytest tests/test_teach.py → 14 passed, 3 skipped
  • full pytest (without the bundled models) → unchanged; the only failure, tests/test_faces.py::test_a_downloaded_model_not_in_use_can_be_deleted, fails the same way on master (it needs the downloaded-model layout).
  • ruff check and ruff format --check clean on the changed files.

Fixes #45

Note: this change was prepared by an AI agent under human direction and review.

An object sensor builds its taught index from the stored images of its
taught boxes. When one of those images has disappeared (a partly restored
data directory, an external clean-up), imaging.load raised FileNotFoundError
and the whole index build failed, so the sensor stopped matching anything
at all.

Skip the boxes whose image is gone and build the index from the ones still
there, logging which were dropped. This matches how the rest of the app
already tolerates a missing image (see imaging.load, and the import path
that skips a broken sample).

Fixes oleost#45

Signed-off-by: wzd8888 <wzd8888@users.noreply.github.com>
@oleost

oleost commented Oct 14, 2026

Copy link
Copy Markdown
Owner

@wzd8888 Thanks for your PR, did take most of it, but added some additional changes. Its live in latest beta (0.9.1b3) and will soon hopefully be pushed to stable.

@oleost oleost closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No such file or directory

2 participants