Skip to content

Commit 9938188

Browse files
committed
Remove instanceId field
1 parent a896014 commit 9938188

File tree

7 files changed

+10
-42
lines changed

7 files changed

+10
-42
lines changed

docs/docs/03-hooks/02-computer-vision/useInstanceSegmentation.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ It is recommended to use models provided by us, which are available at our [Hugg
1515
## High Level Overview
1616

1717
```typescript
18-
import { useInstanceSegmentation } from 'react-native-executorch';
18+
import { useInstanceSegmentation, YOLO26N_SEG } from 'react-native-executorch';
1919

2020
const model = useInstanceSegmentation({
21-
model: {
22-
modelName: 'yolo26n-seg',
23-
modelSource: 'https://huggingface.co/.../yolo26n-seg.pte',
24-
},
21+
model: YOLO26N_SEG,
2522
});
2623

2724
const imageUri = 'file:///Users/.../photo.jpg';
@@ -39,7 +36,7 @@ try {
3936
`useInstanceSegmentation` takes [`InstanceSegmentationProps`](../../06-api-reference/interfaces/InstanceSegmentationProps.md) that consists of:
4037

4138
- `model` - An object containing:
42-
- `modelName` - The name of a built-in model. See [`InstanceSegmentationModelSources`](../../06-api-reference/interfaces/InstanceSegmentationProps.md) for the list of supported models.
39+
- `modelName` - The name of a built-in model. See [`InstanceSegmentationModelName`](../../06-api-reference/types/InstanceSegmentationModelName.md) for the list of supported models.
4340
- `modelSource` - The location of the model binary (a URL or a bundled resource).
4441
- An optional flag [`preventLoad`](../../06-api-reference/interfaces/InstanceSegmentationProps.md#preventload) which prevents auto-loading of the model.
4542

@@ -78,19 +75,15 @@ To run the model, use the [`forward`](../../06-api-reference/interfaces/Instance
7875
- `mask` - A `Uint8Array` binary mask (0 or 1) representing the instance's segmentation.
7976
- `maskWidth` - Width of the mask array.
8077
- `maskHeight` - Height of the mask array.
81-
- `instanceId` - Unique identifier for this instance.
8278

8379
## Example
8480

8581
```typescript
86-
import { useInstanceSegmentation } from 'react-native-executorch';
82+
import { useInstanceSegmentation, YOLO26N_SEG } from 'react-native-executorch';
8783

8884
function App() {
8985
const model = useInstanceSegmentation({
90-
model: {
91-
modelName: 'yolo26n-seg',
92-
modelSource: 'https://huggingface.co/.../yolo26n-seg.pte',
93-
},
86+
model: YOLO26N_SEG,
9487
});
9588

9689
const handleSegment = async () => {

packages/react-native-executorch/common/rnexecutorch/host_objects/JsiConversions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ getJsiValue(const std::vector<models::instance_segmentation::types::Instance>
487487
instance.setProperty(runtime, "classIndex", instances[i].classIndex);
488488

489489
instance.setProperty(runtime, "score", instances[i].score);
490-
instance.setProperty(runtime, "instanceId", instances[i].instanceId);
491490

492491
array.setValueAtIndex(runtime, i, instance);
493492
}

packages/react-native-executorch/common/rnexecutorch/models/instance_segmentation/BaseInstanceSegmentation.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ std::vector<types::Instance> BaseInstanceSegmentation::finalizeInstances(
284284
instances.resize(maxInstances);
285285
}
286286

287-
for (int32_t i = 0; std::cmp_less(i, instances.size()); ++i) {
288-
instances[i].instanceId = i;
289-
}
290-
291287
return instances;
292288
}
293289

@@ -357,7 +353,7 @@ std::vector<types::Instance> BaseInstanceSegmentation::postprocess(
357353
bboxOriginal,
358354
std::vector<uint8_t>(binaryMask.data,
359355
binaryMask.data + binaryMask.total()),
360-
binaryMask.cols, binaryMask.rows, labelIdx, score, i);
356+
binaryMask.cols, binaryMask.rows, labelIdx, score);
361357
}
362358

363359
return finalizeInstances(std::move(instances), iouThreshold, maxInstances);

packages/react-native-executorch/common/rnexecutorch/models/instance_segmentation/Types.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace rnexecutorch::models::instance_segmentation::types {
1010
* Represents a single detected instance in instance segmentation output.
1111
*
1212
* Contains bounding box coordinates, binary segmentation mask, class label,
13-
* confidence score, and a unique instance identifier.
13+
* and confidence score.
1414
*/
1515
struct Instance {
1616
utils::computer_vision::BBox bbox; ///< Bounding box coordinates
@@ -19,15 +19,13 @@ struct Instance {
1919
int32_t maskHeight; ///< Height of the mask array
2020
int32_t classIndex; ///< Model output class index
2121
float score; ///< Confidence score [0, 1]
22-
int32_t instanceId; ///< Unique identifier for this instance
2322

2423
Instance() = default;
2524
Instance(utils::computer_vision::BBox bbox, std::vector<uint8_t> mask,
2625
int32_t maskWidth, int32_t maskHeight, int32_t classIndex,
27-
float score, int32_t instanceId)
26+
float score)
2827
: bbox(bbox), mask(std::move(mask)), maskWidth(maskWidth),
29-
maskHeight(maskHeight), classIndex(classIndex), score(score),
30-
instanceId(instanceId) {}
28+
maskHeight(maskHeight), classIndex(classIndex), score(score) {}
3129
};
3230

3331
} // namespace rnexecutorch::models::instance_segmentation::types

packages/react-native-executorch/common/rnexecutorch/tests/integration/InstanceSegmentationTest.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,6 @@ TEST(InstanceSegResultTests, InstancesHaveValidMasks) {
170170
}
171171
}
172172

173-
TEST(InstanceSegResultTests, InstancesHaveUniqueIds) {
174-
BaseInstanceSegmentation model(kValidInstanceSegModelPath, {}, {}, true,
175-
nullptr);
176-
auto results =
177-
model.generate(kValidTestImagePath, 0.3, 0.5, 100, {}, true, kMethodName);
178-
179-
std::set<int> ids;
180-
for (const auto &inst : results) {
181-
EXPECT_TRUE(ids.insert(inst.instanceId).second)
182-
<< "Duplicate instanceId: " << inst.instanceId;
183-
}
184-
}
185-
186173
TEST(InstanceSegResultTests, InstancesHaveValidClassIndices) {
187174
BaseInstanceSegmentation model(kValidInstanceSegModelPath, {}, {}, true,
188175
nullptr);

packages/react-native-executorch/src/modules/computer_vision/InstanceSegmentationModule.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ export class InstanceSegmentationModule<
343343
label: (labelLookup[inst.classIndex - labelEnumOffset] ??
344344
String(inst.classIndex)) as keyof ResolveLabels<T>,
345345
score: inst.score,
346-
instanceId: inst.instanceId,
347346
}));
348347
};
349348
}
@@ -357,7 +356,7 @@ export class InstanceSegmentationModule<
357356
*
358357
* @param input - Image source (string path or PixelData object)
359358
* @param options - Optional configuration for the segmentation process. Includes `confidenceThreshold`, `iouThreshold`, `maxInstances`, `classesOfInterest`, `returnMaskAtOriginalResolution`, and `inputSize`.
360-
* @returns A Promise resolving to an array of {@link SegmentedInstance} objects with `bbox`, `mask`, `maskWidth`, `maskHeight`, `label`, `score`, and `instanceId`.
359+
* @returns A Promise resolving to an array of {@link SegmentedInstance} objects with `bbox`, `mask`, `maskWidth`, `maskHeight`, `label`, `score`.
361360
* @throws {RnExecutorchError} If the model is not loaded or if an invalid `inputSize` is provided.
362361
*
363362
* @example
@@ -455,7 +454,6 @@ export class InstanceSegmentationModule<
455454
inst.classIndex - this.labelEnumOffset
456455
) ?? String(inst.classIndex)) as keyof ResolveLabels<T>,
457456
score: inst.score,
458-
instanceId: inst.instanceId,
459457
}));
460458
}
461459
}

packages/react-native-executorch/src/types/instanceSegmentation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export interface NativeSegmentedInstance {
1515
maskHeight: number;
1616
classIndex: number;
1717
score: number;
18-
instanceId: number;
1918
}
2019

2120
/**
@@ -29,7 +28,6 @@ export interface NativeSegmentedInstance {
2928
* @property {number} maskHeight - Height of the mask array.
3029
* @property {keyof L} label - The class label of the instance.
3130
* @property {number} score - Confidence score [0, 1].
32-
* @property {number} instanceId - Unique identifier for this instance.
3331
*/
3432
export interface SegmentedInstance<L extends LabelEnum> {
3533
bbox: Bbox;
@@ -38,7 +36,6 @@ export interface SegmentedInstance<L extends LabelEnum> {
3836
maskHeight: number;
3937
label: keyof L;
4038
score: number;
41-
instanceId: number;
4239
}
4340

4441
/**

0 commit comments

Comments
 (0)