Skip to content

Commit 8398ee9

Browse files
committed
Split instance segmentation postprocessing, introduce CV utils
1 parent 2a55b8d commit 8398ee9

File tree

10 files changed

+317
-202
lines changed

10 files changed

+317
-202
lines changed

apps/computer-vision/app/instance_segmentation/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ export default function InstanceSegmentationScreen() {
7474
inputSize: selectedInputSize ?? undefined,
7575
});
7676

77-
console.log('Output is ', output[0].label);
78-
7977
// Convert raw masks → small Skia images immediately.
8078
// Raw Uint8Array mask buffers (backed by native OwningArrayBuffer)
8179
// go out of scope here and become eligible for GC right away.

packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "RnExecutorchInstaller.h"
22

3-
#include <iostream>
43
#include <rnexecutorch/TokenizerModule.h>
54
#include <rnexecutorch/host_objects/JsiConversions.h>
65
#include <rnexecutorch/models/classification/Classification.h>

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <rnexecutorch/models/speech_to_text/types/Segment.h>
2323
#include <rnexecutorch/models/speech_to_text/types/TranscriptionResult.h>
2424
#include <rnexecutorch/models/voice_activity_detection/Types.h>
25+
#include <rnexecutorch/utils/computer_vision/Types.h>
2526

2627
using namespace rnexecutorch::models::speech_to_text::types;
2728

@@ -429,6 +430,16 @@ getJsiValue(const std::unordered_map<std::string_view, float> &map,
429430
return mapObj;
430431
}
431432

433+
inline jsi::Value getJsiValue(const utils::computer_vision::BBox &bbox,
434+
jsi::Runtime &runtime) {
435+
jsi::Object obj(runtime);
436+
obj.setProperty(runtime, "x1", bbox.x1);
437+
obj.setProperty(runtime, "y1", bbox.y1);
438+
obj.setProperty(runtime, "x2", bbox.x2);
439+
obj.setProperty(runtime, "y2", bbox.y2);
440+
return obj;
441+
}
442+
432443
inline jsi::Value getJsiValue(
433444
const std::vector<models::object_detection::types::Detection> &detections,
434445
jsi::Runtime &runtime) {
@@ -459,13 +470,8 @@ inline jsi::Value getJsiValue(
459470
for (std::size_t i = 0; i < instances.size(); ++i) {
460471
jsi::Object instance(runtime);
461472

462-
// Bbox
463-
jsi::Object bbox(runtime);
464-
bbox.setProperty(runtime, "x1", instances[i].x1);
465-
bbox.setProperty(runtime, "y1", instances[i].y1);
466-
bbox.setProperty(runtime, "x2", instances[i].x2);
467-
bbox.setProperty(runtime, "y2", instances[i].y2);
468-
instance.setProperty(runtime, "bbox", bbox);
473+
instance.setProperty(runtime, "bbox",
474+
getJsiValue(instances[i].bbox, runtime));
469475

470476
// Mask as Uint8Array
471477
auto maskBuffer = std::make_shared<OwningArrayBuffer>(

0 commit comments

Comments
 (0)