File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -2204,12 +2204,17 @@ export class ImageSegmentationPipeline extends (/** @type {new (options: ImagePi
22042204 /** @type {ImageSegmentationPipelineOutput[] } */
22052205 const annotation = [ ] ;
22062206 if ( ! subtask ) {
2207+ // We define an epsilon to safeguard against numerical/precision issues when detecting
2208+ // the normalization mode of the output (i.e., sigmoid already applied, or not).
2209+ // See https://github.com/microsoft/onnxruntime/issues/23943 for more information.
2210+ const epsilon = 1e-5 ;
2211+
22072212 // Perform standard image segmentation
22082213 const result = output [ outputNames [ 0 ] ] ;
22092214 for ( let i = 0 ; i < imageSizes . length ; ++ i ) {
22102215 const size = imageSizes [ i ] ;
22112216 const item = result [ i ] ;
2212- if ( item . data . some ( x => x < 0 || x > 1 ) ) {
2217+ if ( item . data . some ( x => x < - epsilon || x > 1 + epsilon ) ) {
22132218 item . sigmoid_ ( ) ;
22142219 }
22152220 const mask = await RawImage . fromTensor ( item . mul_ ( 255 ) . to ( 'uint8' ) ) . resize ( size [ 1 ] , size [ 0 ] ) ;
You can’t perform that action at this time.
0 commit comments