Draft
Conversation
84f6e93 to
1953373
Compare
2d33d1d to
7a0e899
Compare
1953373 to
6a090e7
Compare
Add initNormalization, createInputTensor, loadImageToRGB, loadFrameRotated, and loadFrameRotatedWithSize helpers to eliminate duplication across vision models.
Remove duplicated preprocessing code from ImageEmbeddings, Classification, StyleTransfer, ObjectDetection, BaseInstanceSegmentation, and BaseSemanticSegmentation (~105 lines removed).
Add ensureMethodLoaded, getModelInputSize, and currentlyLoadedMethod_ to support models with multiple methods (e.g., forward_384, forward_512).
…sing
Add prepareAllowedClasses and validateThreshold to Processing.{h,cpp} for reuse across detection models.
Simplify calculateModelImageSize to use BaseModel's getModelInputSize helper (~7 lines removed).
Centralize input shape validation logic across all models. Replaces duplicated validation code in 7 models (~84 lines removed).
Add documentation explaining when subclasses should: - Call initNormalization() for models expecting ImageNet preprocessing - Skip it for models with built-in normalization or raw input - Note that createInputTensor() safely handles both cases via std::optional
Create header-only utility for converting tensors to std::span. Provides: - toSpan<T>(Tensor&): Convert tensor to typed span - toSpan<T>(EValue&): Extract tensor from EValue then convert Eliminates manual pointer arithmetic and improves type safety. Replaces 8+ manual span constructions across vision models.
Add utility function to extract bbox, score, and label from detection model tensor outputs. Replaces private extractDetectionData() method in BaseInstanceSegmentation. Provides reusable data extraction for detection models.
Add template function to apply inverse rotation to bboxes in containers. Provides convenience helper for batch operations on detection/segmentation results, eliminating manual loops in ObjectDetection and InstanceSegmentation.
Add convenience methods to reduce error-checking boilerplate: - forwardOrThrow(EValue): Execute forward with single input - forwardOrThrow(vector<EValue>): Execute forward with multiple inputs - executeOrThrow(string, vector<EValue>): Execute named method All methods throw RnExecutorchError on failure with customizable messages. Replaces 4+ manual error-checking patterns across vision models.
Replace manual tensor-to-span conversion with utils::tensor::toSpan. Replace forward error checking with forwardOrThrow helper. Simplifies code and improves consistency with new utility patterns.
Replace manual tensor-to-span conversion with utils::tensor::toSpan. Replace forward error checking with forwardOrThrow helper. Simplifies code and improves consistency with new utility patterns.
Replace 3 manual tensor-to-span conversions with utils::tensor::toSpan. Replace execute error checking with executeOrThrow helper. Replace rotation loop with utils::inverseRotateBboxes batch helper. Simplifies code and improves consistency with new utility patterns.
Replace execute error checking with executeOrThrow helper. Replace private extractDetectionData with utils::computer_vision version. Delete duplicate extractDetectionData method (now in shared utils). Replace bbox rotation loop with utils::inverseRotateBboxes batch helper. Mask rotation remains inline as it's instance-specific logic.
Replace forward error checking with forwardOrThrow helper. Simplifies code and improves consistency with new utility patterns.
Replace forward error checking with forwardOrThrow helper. Simplifies code and improves consistency with new utility patterns.
c7703fe to
5b1a6fa
Compare
Add comprehensive unit tests for refactoring utilities: - TensorHelpersTest: Test toSpan<T> for Tensor and EValue conversions * Float and int32 tensors * Multidimensional tensors * Empty tensors * Type safety and const correctness - ComputerVisionProcessingTest: Test extractDetectionData * Single and multiple detections * Various indices and label formats * Edge cases (negative coords, fractional values) - FrameTransformTest: Test inverseRotateBboxes batch helper * Batch rotation of multiple detections * Empty containers and single detection * Preservation of non-bbox fields Updated CMakeLists.txt to register new test executables.
5b1a6fa to
10e089c
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.
Description
Introduces a breaking change?
Type of change
Tested on
Testing instructions
Screenshots
Related issues
Checklist
Additional notes