@di-framework/ml
v0.1.0
Published
Run a di-ml dist/model.onnx graph (ONNX Runtime Web: WASM, optional WebGPU)
Maintainers
Readme
@di-framework/ml
Load a di-ml dist/model.onnx and run forward inference. WASM CPU by default; pass WebGPU when the host has it.
import { Session } from "@di-framework/ml";
const session = await Session.fromPath("workspace/dist/model.onnx");
const out = await session.run({
input: { data: new Float32Array([0, 1]), dims: [1, 2] },
});Session.fromBytes takes the ONNX blob when there is no filesystem.
await Session.fromBytes(bytes, { executionProviders: ["webgpu", "wasm"] });Train with the Rust CLI; this package does not train.
OCR line recognition (PP-OCRv4 English rec) is the first non-XOR fixture:
import { Session, loadCharset, recognizeLine, renderGlyphLine } from "@di-framework/ml";
const session = await Session.fromPath("../../examples/ocr/models/en_PP-OCRv4_rec_mobile.onnx");
const charset = loadCharset(await Bun.file("../../examples/ocr/en_dict.txt").text());
const { text } = await recognizeLine(session, renderGlyphLine("HELLO"), charset);bun scripts/fetch-ocr-model.ts # from repo root
bun test # in packages/inferThe ONNX is fetched (sha256 pin in examples/ocr/SOURCE.md), not committed. di-ml lints it as P3 vision and will not train it.
