in src/nodes/client/depth-estimation.ts [44:89]
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: { depthData: null } })
);
return;
}
if (this.cachedResult && compareObjects(this.cachedInput, inputs)) {
this.dispatchEvent(
new CustomEvent("outputs", { detail: { depthData: this.cachedResult } })
);
return;
}
this.cachedInput = inputs;
const canvas = services.resourceService.get(
image.canvasId
) as HTMLCanvasElement;
const data = canvas.toDataURL();
const depth_estimator: DepthEstimationPipeline = await this.getInstance(
_modelid,
quantized,
device
);
// Predict depth
const result = await depth_estimator(data);
const resultArray = (
Array.isArray(result) ? result : [result]
) as DepthEstimationPipelineOutput[];
this.cachedResult = resultArray;
const detail: Outputs = { depthData: resultArray };
this.cachedInput = inputs;
this.dispatchEvent(new CustomEvent("outputs", { detail: detail }));
}