Feature/face detection#19
Merged
Merged
Conversation
This commit introduces an optional ONNX face-detection backend, configurable via the PICMAG_FACE_DETECTION_MODEL environment variable. When enabled, the system can detect multiple faces in an image using a specified ONNX model, with configurable detection thresholds, NMS IoU thresholds, and maximum number of faces. Key changes include: PersonRecognition.cs: Integration of OnnxDetectionRuntime for multi-face detection. Implementation of non-maximum suppression (NMS) and Intersection over Union (IoU) for refining detection results. Fallback to a single centered face region if ONNX detection fails or no faces are detected above the threshold. New environment variables for configuring detection parameters: PICMAG_FACE_DETECTION_THRESHOLD, PICMAG_FACE_DETECTION_NMS_IOU, PICMAG_FACE_DETECTION_MAX_FACES. LooksLikeEmbeddingModelPath now checks if the configured detection model path resembles an embedding model to prevent misconfiguration. CreateFallbackEmbedding generates unique fallback embeddings for multiple faces. Program.CommandHandlers.cs: Enhanced person scan report to include fallback_files count and detailed fallback_reasons for cases where ONNX detection or embedding falls back to simpler methods. CHANGELOG.md: Updated to reflect the new ONNX face-detection backend feature. This significantly enhances the person-scan-existing command by providing more robust face detection capabilities and better insights into the analysis process, especially when external ONNX models are utilized.
00a7a7d to
730e3c6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an MVP person-recognition workflow to picmag (face detection + optional ONNX embeddings, SQLite persistence, and CLI commands) and reorganizes documentation/testing to support the new feature set.
Changes:
- Add person-recognition storage tables and CLI commands (
--person-*) including scan/label/train/predict/review flows. - Add unit + integration test coverage for the persistence/CLI workflow, plus dataset tooling and attribution manifest scaffolding.
- Rework top-level README into a quick start and add dedicated docs pages; add CI license-header checking.
Reviewed changes
Copilot reviewed 29 out of 34 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| unittests/QualityAnalyzerTests.cs | Adds MIT license header to unit test file. |
| unittests/PersonRecognitionTablesTests.cs | Adds new unit tests for person recognition tables/workflows. |
| unittests/ImagesTableTests.cs | Adds MIT license header to unit test file. |
| unittests/GlobalUsings.cs | Adds MIT license header to unit test global usings. |
| scripts/download_person_test_images.py | Adds a script to download person images + write an attribution TSV manifest. |
| scripts/check_license_headers.py | Adds a script to enforce license headers across source files. |
| README.md | Replaces full README with a quick-start and links to dedicated docs. |
| picmag/tests/integration_test.sh | Adds an end-to-end person recognition integration test (dataset-gated). |
| picmag/tests/in/5-person/train/.gitkeep | Keeps dataset directory in git without committing images. |
| picmag/tests/in/5-person/README.md | Documents how to provide a local dataset for the person-recognition integration test. |
| picmag/tests/in/5-person/probe/.gitkeep | Keeps dataset directory in git without committing images. |
| picmag/tests/in/5-person/probe-negative/.gitkeep | Keeps dataset directory in git without committing images. |
| picmag/tests/in/5-person/LICENSES.tsv | Adds an attribution manifest for test images. |
| picmag/src/QualityAnalysis.cs | Adds MIT license header to existing source file. |
| picmag/src/Program.cs | Extends CLI usage output with --person-* commands. |
| picmag/src/Program.CommandParser.cs | Parses new person-recognition CLI commands and flags. |
| picmag/src/Program.CommandHandlers.cs | Implements handlers for scan/add/list/label/search/train/predict/review. |
| picmag/src/PersonsTable.cs | Adds persons table + helper methods. |
| picmag/src/PersonRecognition.cs | Adds face detection + optional ONNX embedding runtime and helper logic. |
| picmag/src/PersonProfilesTable.cs | Adds persistence for per-person embedding profiles. |
| picmag/src/PersonPredictionsTable.cs | Adds persistence for predicted person matches and review status. |
| picmag/src/ImageFacesTable.cs | Adds persistence for detected faces + labels + queries for training/prediction. |
| picmag/src/Database.cs | Wires new tables into the Database façade. |
| picmag/picmag.csproj | Bumps version to 0.6.0; adds OnnxRuntime dependency and bundles detector model. |
| picmag/completions/picmag.bash-completion | Extends bash completion for new --person-* commands. |
| docs/shell-completion.md | Adds standalone shell completion documentation. |
| docs/readme-standard.md | Restores the “standard” full README as a separate doc. |
| docs/person-recognition.md | Adds detailed person recognition workflow documentation. |
| docs/packaging.md | Adds packaging documentation page. |
| docs/cli.md | Adds consolidated CLI reference page. |
| CHANGELOG.md | Adds 0.6.0 release notes describing person recognition and license checks. |
| .gitignore | Ignores local real-person dataset images while keeping .gitkeep files. |
| .github/workflows/dotnet.yml | Adds a CI step to check license headers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+50
to
+54
| cmd.CommandText = @"create table if not exists persons( | ||
| id integer primary key autoincrement, | ||
| name text not null unique, | ||
| created_at integer not null | ||
| );"; |
Comment on lines
+324
to
+328
| else if (args[i].StartsWith("-")) | ||
| { | ||
| return false; | ||
| } | ||
| } |
Comment on lines
+912
to
+914
| private static readonly object sync = new object(); | ||
| private static OnnxDetectionRuntime instance; | ||
| private static bool initialized; |
Comment on lines
+149
to
+151
| lines.append( | ||
| f'{target.name}\t{title}\t{url}\t{license_name}\t{license_url}\t{artist}' | ||
| ) |
Comment on lines
+9
to
+10
| obama_probe_02.jpg File:Barack Obama and Gordon Brown in 10 Downing Street.jpg https://upload.wikimedia.org/wikipedia/commons/8/8d/Barack_Obama_and_Gordon_Brown_in_10_Downing_Street.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original Public domain <div class="fn value"> | ||
| <a rel="nofollow" class="external text" href="https://www.flickr.com/people/35591378@N03">The Official White House Photostream</a></div> |
Comment on lines
+14
to
+18
| other_probe_01.jpg Angela Merkel portrait File:Angela Merkel. Tallinn Digital Summit.jpg https://upload.wikimedia.org/wikipedia/commons/b/bf/Angela_Merkel._Tallinn_Digital_Summit.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 2.0 https://creativecommons.org/licenses/by/2.0 <a rel="nofollow" class="external text" href="https://www.flickr.com/people/145047505@N06">EU2017EE Estonian Presidency</a> | ||
| other_probe_02.jpg Joe Biden portrait File:Joe Biden in 1968 Edition of Onondagan Yearbook.jpg https://upload.wikimedia.org/wikipedia/commons/e/ec/Joe_Biden_in_1968_Edition_of_Onondagan_Yearbook.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original Public domain Syracuse University | ||
| other_probe_03.jpg Joe Biden portrait File:Joe Biden presidential portrait.jpg https://upload.wikimedia.org/wikipedia/commons/6/68/Joe_Biden_presidential_portrait.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original Public domain <bdi><a href="https://en.wikipedia.org/wiki/en:Adam_Schultz" class="extiw" title="w:en:Adam Schultz"><span title="American photographer">Adam Schultz</span></a></bdi> | ||
| other_probe_04.jpg Emmanuel Macron portrait File:Emmanuel Macron (cropped).jpg https://upload.wikimedia.org/wikipedia/commons/c/c3/Emmanuel_Macron_%28cropped%29.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 2.0 https://creativecommons.org/licenses/by/2.0 <a rel="nofollow" class="external text" href="https://www.flickr.com/people/145047505@N06">Arno Mikkor, EU2017EE Estonian Presidency</a> | ||
| other_probe_05.jpg Emmanuel Macron portrait File:Emmanuel Macron - June 2025 (3x4 cropped).jpg https://upload.wikimedia.org/wikipedia/commons/4/47/Emmanuel_Macron_-_June_2025_%283x4_cropped%29.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 4.0 https://creativecommons.org/licenses/by/4.0 <a href="https://en.wikipedia.org/wiki/European_Commission" class="extiw" title="w:European Commission">European Commission</a> |
Comment on lines
+19
to
+23
| other_probe_01.jpg File:Angela Merkel. Tallinn Digital Summit.jpg https://upload.wikimedia.org/wikipedia/commons/b/bf/Angela_Merkel._Tallinn_Digital_Summit.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 2.0 https://creativecommons.org/licenses/by/2.0 <a rel="nofollow" class="external text" href="https://www.flickr.com/people/145047505@N06">EU2017EE Estonian Presidency</a> | ||
| other_probe_02.jpg File:Emmanuel Macron (cropped).jpg https://upload.wikimedia.org/wikipedia/commons/c/c3/Emmanuel_Macron_%28cropped%29.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 2.0 https://creativecommons.org/licenses/by/2.0 <a rel="nofollow" class="external text" href="https://www.flickr.com/people/145047505@N06">Arno Mikkor, EU2017EE Estonian Presidency</a> | ||
| other_probe_03.jpg File:Emmanuel Macron - June 2025 (3x4 cropped).jpg https://upload.wikimedia.org/wikipedia/commons/4/47/Emmanuel_Macron_-_June_2025_%283x4_cropped%29.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 4.0 https://creativecommons.org/licenses/by/4.0 <a href="https://en.wikipedia.org/wiki/European_Commission" class="extiw" title="w:European Commission">European Commission</a> | ||
| other_probe_04.jpg File:Emmanuel Macron in 2019.jpg https://upload.wikimedia.org/wikipedia/commons/f/f4/Emmanuel_Macron_in_2019.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original Public domain <a rel="nofollow" class="external text" href="https://www.flickr.com/people/148748355@N05">The White House</a> from Washington, DC | ||
| other_probe_05.jpg File:Emmanuel Macron June 2022 (cropped).jpg https://upload.wikimedia.org/wikipedia/commons/d/d2/Emmanuel_Macron_June_2022_%28cropped%29.jpg?utm_source=commons.wikimedia.org&utm_campaign=imageinfo&utm_content=original CC BY 4.0 https://creativecommons.org/licenses/by/4.0 PRESIDENT OF UKRAINE VOLODYMYR ZELENSKYY Official website |
- debian/copyright: separate per-file license sections for version-RFB-320.onnx (MIT), arcfaceresnet100-8.onnx (Apache-2.0), retinanet-9.onnx (BSD-3-Clause), and test images (CC-BY/PD). Removes the incorrect blanket MIT claim for all files. - docs/model-licenses.md: new file with upstream source references, per-model sha256 checksums, and redistribution notes. - README.md: link to docs/model-licenses.md.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
dd4f5eb to
cbc9037
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.