@@ -31,10 +31,7 @@ const ModelConfigs = {
3131 'yolo26m-seg' : YOLO_SEG_CONFIG ,
3232 'yolo26l-seg' : YOLO_SEG_CONFIG ,
3333 'yolo26x-seg' : YOLO_SEG_CONFIG ,
34- } as const satisfies Record <
35- InstanceSegmentationModelName ,
36- InstanceSegmentationConfig < LabelEnum >
37- > ;
34+ } as const ;
3835
3936/** @internal */
4037type ModelConfigsType = typeof ModelConfigs ;
@@ -90,11 +87,11 @@ export class InstanceSegmentationModule<
9087 T extends InstanceSegmentationModelName | LabelEnum ,
9188> extends BaseModule {
9289 private labelMap : ResolveLabels < T > ;
93- private modelConfig : InstanceSegmentationConfig < ResolveLabels < T > > ;
90+ private modelConfig : InstanceSegmentationConfig < LabelEnum > ;
9491
9592 private constructor (
9693 labelMap : ResolveLabels < T > ,
97- modelConfig : InstanceSegmentationConfig < ResolveLabels < T > > ,
94+ modelConfig : InstanceSegmentationConfig < LabelEnum > ,
9895 nativeModule : unknown
9996 ) {
10097 super ( ) ;
@@ -127,7 +124,7 @@ export class InstanceSegmentationModule<
127124 onDownloadProgress : ( progress : number ) => void = ( ) => { }
128125 ) : Promise < InstanceSegmentationModule < InstanceModelNameOf < C > > > {
129126 const { modelName, modelSource } = config ;
130- const modelConfig = ModelConfigs [ modelName ] ;
127+ const modelConfig = ModelConfigs [ modelName as keyof typeof ModelConfigs ] ;
131128
132129 const paths = await ResourceFetcher . fetch ( onDownloadProgress , modelSource ) ;
133130 if ( ! paths ?. [ 0 ] ) {
@@ -155,9 +152,7 @@ export class InstanceSegmentationModule<
155152
156153 return new InstanceSegmentationModule < InstanceModelNameOf < C > > (
157154 modelConfig . labelMap as ResolveLabels < InstanceModelNameOf < C > > ,
158- modelConfig as InstanceSegmentationConfig <
159- ResolveLabels < InstanceModelNameOf < C > >
160- > ,
155+ modelConfig ,
161156 nativeModule
162157 ) ;
163158 }
@@ -221,7 +216,7 @@ export class InstanceSegmentationModule<
221216
222217 return new InstanceSegmentationModule < L > (
223218 config . labelMap as ResolveLabels < L > ,
224- config as InstanceSegmentationConfig < ResolveLabels < L > > ,
219+ config ,
225220 nativeModule
226221 ) ;
227222 }
@@ -298,6 +293,8 @@ export class InstanceSegmentationModule<
298293 } )
299294 : [ ] ;
300295
296+ // Measure inference time
297+ const startTime = performance . now ( ) ;
301298 const nativeResult = await this . nativeModule . generate (
302299 imageSource ,
303300 confidenceThreshold ,
@@ -307,10 +304,18 @@ export class InstanceSegmentationModule<
307304 returnMaskAtOriginalResolution ,
308305 inputSize // Pass inputSize as number instead of methodName as string
309306 ) ;
307+ const endTime = performance . now ( ) ;
308+ const inferenceTime = endTime - startTime ;
309+
310+ console . log (
311+ `[Instance Segmentation] Inference completed in ${ inferenceTime . toFixed ( 2 ) } ms | Input size: ${ inputSize } x${ inputSize } | Detected: ${ nativeResult . length } instances`
312+ ) ;
310313
311314 // Convert label indices back to label names
312315 // YOLO outputs 0-indexed class IDs, but COCO labels are 1-indexed, so add 1
313- const reverseLabelMap = Object . entries ( this . labelMap ) . reduce (
316+ const reverseLabelMap = Object . entries (
317+ this . labelMap as Record < string , number >
318+ ) . reduce (
314319 ( acc , [ key , value ] ) => {
315320 acc [ value as number ] = key ;
316321 return acc ;
0 commit comments