feat!: make image segmentation generic, general refactor#814
Open
feat!: make image segmentation generic, general refactor#814
Conversation
chmjkb
commented
Feb 17, 2026
Comment on lines
26
to
29
| 'rfdetr': { | ||
| labelMap: CocoLabel, | ||
| preprocessorConfig: { normMean: IMAGENET_MEAN, normStd: IMAGENET_STD }, | ||
| }, |
Collaborator
Author
There was a problem hiding this comment.
fyi this doesnt work as the rfdetr is an instance segmentation model and needs a separate implementation, but leaving this so you can get an idea on what the configuration looks like
This comment was marked as resolved.
This comment was marked as resolved.
msluszniak
requested changes
Feb 17, 2026
...ct-native-executorch/common/rnexecutorch/models/image_segmentation/BaseImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
...ct-native-executorch/common/rnexecutorch/models/image_segmentation/BaseImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
...ct-native-executorch/common/rnexecutorch/models/image_segmentation/BaseImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
...ct-native-executorch/common/rnexecutorch/models/image_segmentation/BaseImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
msluszniak
reviewed
Feb 18, 2026
docs/docs/04-typescript-api/02-computer-vision/ImageSegmentationModule.md
Outdated
Show resolved
Hide resolved
9c0f38e to
6a523df
Compare
msluszniak
approved these changes
Feb 19, 2026
Member
|
There are some conflicts after PR with adapters. |
mkopcins
requested changes
Feb 20, 2026
.../react-native-executorch/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
...eact-native-executorch/common/rnexecutorch/models/image_segmentation/BaseImageSegmentation.h
Show resolved
Hide resolved
packages/react-native-executorch/src/hooks/computer_vision/useImageSegmentation.ts
Show resolved
Hide resolved
| onDownloadProgress: (progress: number) => void = () => {} | ||
| ): Promise<ImageSegmentationModule<L>> { | ||
| const paths = await ResourceFetcher.fetch(onDownloadProgress, modelSource); | ||
| if (!paths?.[0]) { |
Collaborator
There was a problem hiding this comment.
I guess we should be also checking for paths.length == =1
Member
There was a problem hiding this comment.
If so, we need to change this part in the rest of the models as well.
benITo47
reviewed
Feb 20, 2026
...ct-native-executorch/common/rnexecutorch/models/image_segmentation/BaseImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
benITo47
reviewed
Feb 20, 2026
.../react-native-executorch/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp
Outdated
Show resolved
Hide resolved
msluszniak
reviewed
Feb 20, 2026
...ages/react-native-executorch/common/rnexecutorch/models/object_detection/ObjectDetection.cpp
Outdated
Show resolved
Hide resolved
Co-authored-by: Mateusz Kopcinski <120639731+mkopcins@users.noreply.github.com>
f3a48b8 to
3e95f6e
Compare
msluszniak
approved these changes
Feb 23, 2026
msluszniak
requested changes
Feb 23, 2026
Member
msluszniak
left a comment
There was a problem hiding this comment.
There are some errors in compilation of C++ code that spread across multiple models, not only segmentation. So I believe there are some errors maybe in BaseModel or similar location
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
Refactors image segmentation into a generic, multi-model architecture. Previously the module was hardcoded to DeepLab V3 — now it supports multiple built-in models (DeepLab V3, selfie segmentation, RF-DETR) and custom user-provided models with type-safe label maps.
Key changes:
BaseImageSegmentationwith virtualpreprocess()/postprocess()methods.ImageSegmentationis now a thin subclass. This allows future models to override preprocessing (e.g. different normalization) or postprocessing without duplicating the pipeline.readImageToTensornow accepts optionalnormMean/normStdparams, eliminating duplicated normalization logic. also, imo it would be a good idea to do such factories for the entire APIImageSegmentationModule<T>is generic over model name or customLabelEnum. Two static factories:fromModelName()(built-in models with auto label resolution) andfromCustomConfig()(custom models with user-provided labels).useImageSegmentationinfers the model's label types from the config — no explicit generic parameter needed.forward()return type narrows based onclassesOfInterestpassed in.forward()now returnsRecord<'ARGMAX', Int32Array> & Record<K, Float32Array>matching what the native side actually produces (was incorrectly typed asnumber[]).'ARGMAX'fromclassesOfInterest— it's always in the output regardless, and the return type reflects this.Introduces a breaking change?
Type of change
Tested on
Testing instructions
computer-visiondemo appclassesOfInterestshould only suggest valid label keys for the chosen model (e.g.'PERSON','CAR'for DeepLab,'SELFIE'/'BACKGROUND'for selfie segmentation)Screenshots
Related issues
Checklist
Additional notes
The
ImageSegmentationModule.fromCustomConfig()API allows users to bring their own segmentation model with a custom label map: