async runWithInputs()

in src/nodes/client/image-segmentation.ts [46:85]


  async runWithInputs(inputs: Inputs, services: Services) {
    const { image, modelid, device, quantized } = inputs;

    const _modelid = modelid?.trim();
    if (!image?.canvasId) {
      // No input node
      this.dispatchEvent(
        new CustomEvent("outputs", { detail: { segData: null } })
      );
      return;
    }

    if (this.cachedResult && compareObjects(this.cachedInput, inputs)) {
      this.dispatchEvent(
        new CustomEvent("outputs", { detail: { segData: this.cachedResult } })
      );
      return;
    }
    this.cachedInput = inputs;

    // Clear masks
    // this.masks.innerHTML = '';

    const canvas = services.resourceService.get(
      image.canvasId
    ) as HTMLCanvasElement;
    const data = canvas.toDataURL();
    const segmenter: ImageSegmentationPipeline = await this.getInstance(
      _modelid,
      quantized,
      device
    );

    // Predict segments
    const output = await segmenter(data);
    this.cachedResult = output;

    const detail: Outputs = { segData: output };
    this.dispatchEvent(new CustomEvent("outputs", { detail: detail }));
  }