Skip to content

Filter predict outputs to save only test_crop_manifest labels#197

Merged
rhoadesScholar merged 12 commits intomainfrom
copilot/update-model-output-saving
Feb 23, 2026
Merged

Filter predict outputs to save only test_crop_manifest labels#197
rhoadesScholar merged 12 commits intomainfrom
copilot/update-model-output-saving

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

  • Understand the current predict flow and identify the issue
  • Add get_test_crop_labels() function to get labels for each crop
  • Update the predict() function to filter classes per crop when crops="test"
  • Modify _predict() to structure outputs with all model classes but filter before saving
  • Add comprehensive tests to validate the changes
  • Document the changes in docstrings
  • Address all code review feedback
  • Optimize class index lookup (O(1) instead of O(n))
  • Clarify documentation about label filtering behavior
  • Run security checks (CodeQL) - no vulnerabilities found
  • Use cached TEST_CROPS in get_test_crop_labels for performance
  • Add validation to skip crops with no matching labels
  • Add safety check in _predict for empty classes_to_save
  • Add integration tests for filtering behavior with dict and tensor outputs
  • Add end-to-end integration test that calls predict() and verifies filtered output
  • Fix test issues: use pytest.skip() instead of return, improve mock configuration

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update default output saving for model predictions Filter predict outputs to save only test_crop_manifest labels Feb 20, 2026
Copilot AI requested a review from rhoadesScholar February 20, 2026 22:29
@rhoadesScholar rhoadesScholar marked this pull request as ready for review February 21, 2026 01:38
Copilot AI review requested due to automatic review settings February 21, 2026 01:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements filtering of prediction outputs to save only the class labels specified in the test_crop_manifest for each crop when running predict(crops="test"). This optimization reduces storage requirements and processing time by avoiding saving predictions for classes that won't be scored.

Changes:

  • Added get_test_crop_labels() utility function to retrieve scored labels per crop from the test manifest
  • Modified predict() to filter classes to the intersection of model classes and crop-specific labels when crops="test"
  • Modified _predict() to structure outputs using all model classes but filter them before disk write

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/cellmap_segmentation_challenge/utils/crops.py Added get_test_crop_labels() function to retrieve class labels for a specific test crop from the manifest
src/cellmap_segmentation_challenge/utils/init.py Exported the new get_test_crop_labels function
src/cellmap_segmentation_challenge/predict.py Modified prediction pipeline to filter outputs based on test_crop_manifest labels; added support for model_classes parameter to maintain model compatibility while filtering saved classes
tests/test_crops.py Added comprehensive unit tests for get_test_crop_labels() covering various scenarios including edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rhoadesScholar
Copy link
Member

@copilot apply changes based on the comments in this thread

Copy link
Contributor Author

Copilot AI commented Feb 23, 2026

@copilot apply changes based on the comments in this thread

Fixed all issues in 2ee6319:

  1. test_crops.py: Replaced all return statements with pytest.skip() in tests that check prerequisites (comments 2841862962, 2841862980, 2841862999, 2841863014, 2841863095). Tests now explicitly report as skipped when manifest is unavailable.

  2. test_predict_filtering.py:

    • Fixed mock configuration (comment 2841863045): Changed from mock_model.__call__ = mock_forward to mock_model.side_effect = mock_forward for proper mock behavior
    • Removed broad exception handling (comment 2841863074): Now mocks _predict function directly to capture dataset_writer_kwargs, eliminating need for try/except and making test failures more explicit

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rhoadesScholar rhoadesScholar merged commit 442bf18 into main Feb 23, 2026
11 checks passed
@rhoadesScholar rhoadesScholar deleted the copilot/update-model-output-saving branch February 23, 2026 19:57
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.

3 participants