{"version":3,"file":"labels.cjs","names":[],"sources":["../../src/vision/labels.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Class label resolution: presets, lists, dicts, or auto-generated.\n *\n * Tasks call {@link resolveLabels} once at construction time to turn whatever\n * the caller passed (preset name, array, dict, or `null`) into an ordered\n * array of class names indexed by class id.\n *\n * In the browser there is no filesystem, so this module does not load labels\n * from a path — fetch the file yourself and pass an array.\n */\n\nimport { LabelMapError } from \"./core/exceptions\";\n\n/**\n * Anything accepted by {@link resolveLabels}.\n *\n * - `string[]` / `readonly string[]`: explicit names indexed by class id.\n * - `Record<number, string>`: sparse mapping (gaps filled with `class_<id>`).\n * - `string`: a preset name (e.g. `\"coco\"`).\n * - `null` / `undefined`: auto-generate `class_0` ... `class_{numClasses-1}`.\n */\nexport type LabelSpec = readonly string[] | Record<number, string> | string | null | undefined;\n\n/** COCO 2017 80-class labels in canonical class-id order. */\nexport const COCO_CLASSES: readonly string[] = Object.freeze([\n    \"person\",\n    \"bicycle\",\n    \"car\",\n    \"motorcycle\",\n    \"airplane\",\n    \"bus\",\n    \"train\",\n    \"truck\",\n    \"boat\",\n    \"traffic light\",\n    \"fire hydrant\",\n    \"stop sign\",\n    \"parking meter\",\n    \"bench\",\n    \"bird\",\n    \"cat\",\n    \"dog\",\n    \"horse\",\n    \"sheep\",\n    \"cow\",\n    \"elephant\",\n    \"bear\",\n    \"zebra\",\n    \"giraffe\",\n    \"backpack\",\n    \"umbrella\",\n    \"handbag\",\n    \"tie\",\n    \"suitcase\",\n    \"frisbee\",\n    \"skis\",\n    \"snowboard\",\n    \"sports ball\",\n    \"kite\",\n    \"baseball bat\",\n    \"baseball glove\",\n    \"skateboard\",\n    \"surfboard\",\n    \"tennis racket\",\n    \"bottle\",\n    \"wine glass\",\n    \"cup\",\n    \"fork\",\n    \"knife\",\n    \"spoon\",\n    \"bowl\",\n    \"banana\",\n    \"apple\",\n    \"sandwich\",\n    \"orange\",\n    \"broccoli\",\n    \"carrot\",\n    \"hot dog\",\n    \"pizza\",\n    \"donut\",\n    \"cake\",\n    \"chair\",\n    \"couch\",\n    \"potted plant\",\n    \"bed\",\n    \"dining table\",\n    \"toilet\",\n    \"tv\",\n    \"laptop\",\n    \"mouse\",\n    \"remote\",\n    \"keyboard\",\n    \"cell phone\",\n    \"microwave\",\n    \"oven\",\n    \"toaster\",\n    \"sink\",\n    \"refrigerator\",\n    \"book\",\n    \"clock\",\n    \"vase\",\n    \"scissors\",\n    \"teddy bear\",\n    \"hair drier\",\n    \"toothbrush\",\n]);\n\nconst PRESETS: Readonly<Record<string, readonly string[]>> = {\n    coco: COCO_CLASSES,\n};\n\nexport interface ResolveLabelsOptions {\n    /**\n     * Expected number of classes.\n     *\n     * - When `spec` is `null`/`undefined`, this is required to auto-generate names.\n     * - When `spec` is provided, it validates that the resolved length matches.\n     */\n    readonly numClasses?: number;\n}\n\n/**\n * Resolve a labels specification into an ordered array of class names.\n *\n * @throws {@link LabelMapError} if the spec is invalid, the preset is unknown,\n *   or the resolved length disagrees with `numClasses`.\n */\n/**\n * Pick the fallback label spec for a model that declares no class names.\n *\n * The COCO preset is the right default for a stock YOLO export and an\n * impossible one for anything else: it names exactly 80 classes, so handing it\n * to a 3-class head makes {@link resolveLabels} throw `Resolved 80 labels but\n * the model has 3 classes` and the task cannot be created at all. A custom\n * model without baked-in `names` is an ordinary thing to have — it should come\n * up as `class_0`, `class_1`, ..., not as a failure.\n *\n * @param numClasses Classes the model predicts, or `undefined` when the output\n *   shape does not say.\n * @returns `\"coco\"` when the preset can describe the model, otherwise `null`,\n *   which makes {@link resolveLabels} generate `class_N` names.\n */\nexport function defaultLabels(numClasses: number | undefined): LabelSpec {\n    if (numClasses === undefined || numClasses === COCO_CLASSES.length) {\n        return \"coco\";\n    }\n    return null;\n}\n\nexport function resolveLabels(\n    spec: LabelSpec,\n    options: ResolveLabelsOptions = {},\n): readonly string[] {\n    const labels = resolve(spec, options.numClasses);\n    if (options.numClasses !== undefined && labels.length !== options.numClasses) {\n        throw new LabelMapError(\n            `Resolved ${labels.length} labels but the model has ${options.numClasses} classes.`,\n        );\n    }\n    return labels;\n}\n\nfunction resolve(spec: LabelSpec, numClasses: number | undefined): readonly string[] {\n    if (spec === null || spec === undefined) {\n        if (numClasses === undefined) {\n            throw new LabelMapError(\n                \"Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.\",\n            );\n        }\n        return Array.from({ length: numClasses }, (_, i) => `class_${i}`);\n    }\n\n    if (Array.isArray(spec)) {\n        return [...spec];\n    }\n\n    if (typeof spec === \"string\") {\n        const preset = PRESETS[spec];\n        if (preset !== undefined) {\n            return preset;\n        }\n        throw new LabelMapError(\n            `Unknown labels preset: ${JSON.stringify(spec)}. Known presets: ${Object.keys(PRESETS).join(\", \")}.`,\n        );\n    }\n\n    if (typeof spec === \"object\") {\n        const map = spec as Record<number, string>;\n        const ids = Object.keys(map).map((k) => Number(k));\n        if (ids.length === 0) {\n            return [];\n        }\n        const maxId = Math.max(...ids);\n        return Array.from({ length: maxId + 1 }, (_, i) => map[i] ?? `class_${i}`);\n    }\n\n    throw new LabelMapError(`Unsupported labels spec type: ${typeof spec}.`);\n}\n"],"mappings":"yCAyBA,IAAa,EAAkC,OAAO,OAAO,wnBAiF7D,CAAC,EAEK,EAAuD,CACzD,KAAM,CACV,EAiCA,SAAgB,EAAc,EAA2C,CAIrE,OAHI,IAAe,IAAA,IAAa,IAAe,EAAa,OACjD,OAEJ,IACX,CAEA,SAAgB,EACZ,EACA,EAAgC,CAAC,EAChB,CACjB,IAAM,EAAS,EAAQ,EAAM,EAAQ,UAAU,EAC/C,GAAI,EAAQ,aAAe,IAAA,IAAa,EAAO,SAAW,EAAQ,WAC9D,MAAM,IAAI,EAAA,cACN,YAAY,EAAO,OAAO,4BAA4B,EAAQ,WAAW,UAC7E,EAEJ,OAAO,CACX,CAEA,SAAS,EAAQ,EAAiB,EAAmD,C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