ISNet General Use model session for high-quality background removal.

ISNet (Interactive Segmentation Network) provides superior quality background removal with better edge detection and detail preservation. Uses larger input resolution (1024x1024) for higher quality results.

Example

// Create an ISNet session
const session = new IsNetGeneralUseSession();

// Or with custom options
const session = new IsNetGeneralUseSession({
preferWebNN: true,
webnnDeviceType: 'gpu'
});

// Initialize and use
await session.initialize();
const masks = await session.predict(imageCanvas);

Hierarchy (view full)

Constructors

Methods

  • Initialize the ONNX session

    If ONNX profiling is enabled (via rembgConfig.enableONNXProfiling(true)), ONNX Runtime will collect profiling data for each inference run. Profiling data is automatically outputted to the console after each inference.

    Returns Promise<void>

  • Parameters

    • imageCanvas: HTMLCanvasElement

    Returns {
        [inputName: string]: ort.Tensor;
    }

    • [inputName: string]: ort.Tensor
  • Parameters

    • input: {
          [inputName: string]: ort.Tensor;
      }
      • [inputName: string]: ort.Tensor

    Returns Promise<OnnxValueMapType>

  • Predict masks for input image

    Parameters

    • imageCanvas: HTMLCanvasElement

    Returns Promise<HTMLCanvasElement[]>

  • generic model output processing

    Most models output a single tensor with shape [1, 1, height, width] This method extracts the data from the tensor and returns it as a Float32Array

    Parameters

    • outputs: OnnxValueMapType

      Model outputs

    Returns Float32Array<ArrayBufferLike>[]

    [Mask array]

  • Generic mask array to mask canvas processing

    Most models just normalize, resize and return the result as a mask canvas.

    Parameters

    • maskArray: Float32Array<ArrayBufferLike>

      Model output mask array

    • originalSize: {
          width: number;
          height: number;
      }

      Original image dimensions for resizing

      • width: number
      • height: number

    Returns HTMLCanvasElement

    HTMLCanvasElement