U2Net Cloth Segmentation model session.

Specialized version of U2Net trained for clothing segmentation. Can segment different types of clothing (upper body, lower body, full body) and is particularly useful for fashion applications and clothing analysis.

Example

// Create a cloth segmentation session
const session = new U2NetClothSegSession();

// Set clothing category
session.setClothCategory('upper');

// 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[]>

  • Set the cloth category filter for this session

    Parameters

    • category: "upper" | "lower" | "full" | "all" | "combined"

    Returns void

  • Get the current cloth category setting

    Returns "upper" | "lower" | "full" | "all" | "combined"

  • Process U2Net Cloth Segmentation model outputs to create masks as Float32Array Returns 3 masks: upper, lower, and full body cloth segmentation

    Parameters

    • outputs: OnnxValueMapType

    Returns Float32Array<ArrayBufferLike>[]

  • Process mask array to create 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