Skip to content

Commit b666041

Browse files
authored
ITEP-66305 - Prepare to move ritm tool (#640)
1 parent 5e55a3c commit b666041

File tree

10 files changed

+29
-9
lines changed

10 files changed

+29
-9
lines changed

web_ui/packages/smart-tools/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ export {
2525
getPointsFromMat,
2626
getMatFromPoints,
2727
} from './src/utils/tool-utils';
28+
29+
export { sessionParams, type SessionParameters } from './src/utils/wasm-utils';
30+
31+
export const RITMModels = {
32+
main: new URL('./src/ritm/models/main.onnx', import.meta.url).toString(),
33+
preprocess: new URL('./src/ritm/models/preprocess.onnx', import.meta.url).toString(),
34+
};
35+
36+
export const SegmentAnythingModels = {
37+
encoder: new URL('./src/segment-anything/models/mobile_sam.encoder.onnx', import.meta.url).toString(),
38+
decoder: new URL('./src/segment-anything/models/sam_vit_h_4b8939.decoder.onnx', import.meta.url).toString(),
39+
};
File renamed without changes.
File renamed without changes.

web_ui/src/webworkers/segment-anything/mobile_sam.encoder.onnx renamed to web_ui/packages/smart-tools/src/segment-anything/models/mobile_sam.encoder.onnx

File renamed without changes.

web_ui/src/webworkers/segment-anything/sam_vit_h_4b8939.decoder.onnx renamed to web_ui/packages/smart-tools/src/segment-anything/models/sam_vit_h_4b8939.decoder.onnx

File renamed without changes.
File renamed without changes.

web_ui/src/pages/annotator/tools/segment-anything-tool/model/session.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Copyright (C) 2022-2025 Intel Corporation
22
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33

4-
import { loadSource } from '@geti/smart-tools';
4+
import { loadSource, SessionParameters, sessionParams } from '@geti/smart-tools';
55
import type { InferenceSession } from 'onnxruntime-common';
66
import * as ort from 'onnxruntime-web';
77

8-
import { SessionParameters, sessionParams } from '../../wasm-utils';
9-
108
const loadModel = async (modelPath: string) => {
119
return await (await loadSource(modelPath))?.arrayBuffer();
1210
};

web_ui/src/setupTests.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,11 @@ jest.mock('@geti/core/src/services/use-deployment-config-query.hook', () => ({
144144
}));
145145

146146
process.env.REACT_APP_VALIDATION_COMPONENT_TESTS = 'true';
147+
148+
jest.mock('@geti/smart-tools', () => ({
149+
sessionParams: {
150+
numThreads: 0,
151+
executionProviders: ['cpu'],
152+
wasmRoot: {},
153+
},
154+
}));

web_ui/src/webworkers/ritm.worker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
isPolygonValid,
1010
loadSource,
1111
OpenCVLoader,
12+
RITMModels,
13+
sessionParams,
1214
stackPlanes,
1315
} from '@geti/smart-tools';
1416
import { Point, Polygon, Shape, ShapeType } from '@geti/smart-tools/src/shared/interfaces';
@@ -20,7 +22,6 @@ import type OpenCVTypes from 'OpenCVTypes';
2022

2123
import { RegionOfInterest } from '../core/annotations/annotation.interface';
2224
import { RITMContour, RITMPoint, TEMPLATE_SIZE } from '../pages/annotator/tools/ritm-tool/ritm-tool.interface';
23-
import { sessionParams } from '../pages/annotator/tools/wasm-utils';
2425

2526
declare const self: DedicatedWorkerGlobalScope;
2627

@@ -48,9 +49,10 @@ class RITM {
4849

4950
async load() {
5051
ort.env.wasm.wasmPaths = sessionParams.wasmRoot;
52+
5153
this.models = {
52-
main: await this.loadModel(new URL('./ritm/main.onnx', import.meta.url).toString()),
53-
preprocess: await this.loadModel(new URL('./ritm/preprocess.onnx', import.meta.url).toString()),
54+
main: await this.loadModel(RITMModels.main),
55+
preprocess: await this.loadModel(RITMModels.preprocess),
5456
};
5557
}
5658

web_ui/src/webworkers/segment-anything.worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// Dependencies get bundled into the worker
55

6-
import { OpenCVLoader } from '@geti/smart-tools';
6+
import { OpenCVLoader, SegmentAnythingModels } from '@geti/smart-tools';
77
import { expose } from 'comlink';
88
import type OpenCVTypes from 'OpenCVTypes';
99

@@ -50,8 +50,8 @@ class SegmentAnythingModelWrapper {
5050
padSize: 1024,
5151
},
5252
modelPaths: new Map([
53-
['encoder', new URL('./segment-anything/mobile_sam.encoder.onnx', import.meta.url).toString()],
54-
['decoder', new URL('./segment-anything/sam_vit_h_4b8939.decoder.onnx', import.meta.url).toString()],
53+
['encoder', SegmentAnythingModels.encoder],
54+
['decoder', SegmentAnythingModels.decoder],
5555
]),
5656
};
5757

0 commit comments

Comments
 (0)