Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,450 Bytes
94753b6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import { InferenceOutputError } from "../../lib/InferenceOutputError";
import type { BaseArgs, Options } from "../../types";
import { request } from "../custom/request";
export type ImageSegmentationArgs = BaseArgs & {
/**
* Binary image data
*/
data: Blob | ArrayBuffer;
};
export interface ImageSegmentationOutputValue {
/**
* The label for the class (model specific) of a segment.
*/
label: string;
/**
* A str (base64 str of a single channel black-and-white img) representing the mask of a segment.
*/
mask: string;
/**
* A float that represents how likely it is that the detected object belongs to the given class.
*/
score: number;
}
export type ImageSegmentationOutput = ImageSegmentationOutputValue[];
/**
* This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
* Recommended model: facebook/detr-resnet-50-panoptic
*/
export async function imageSegmentation(
args: ImageSegmentationArgs,
options?: Options
): Promise<ImageSegmentationOutput> {
const res = await request<ImageSegmentationOutput>(args, {
...options,
taskHint: "image-segmentation",
});
const isValidOutput =
Array.isArray(res) &&
res.every((x) => typeof x.label === "string" && typeof x.mask === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new InferenceOutputError("Expected Array<{label: string, mask: string, score: number}>");
}
return res;
}
|