mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-31 23:27:43 +00:00
* add web * add script and test * fix lint * add test/data/ops * add test/data/node/ to gitignore * modify scripts * add onnxjs * fix tests * fix test-runner * fix sourcemap * fix onnxjs profiling * update test list * update README * resolve comments * set wasm as default backend * rename package * update copyright header * do not use class "Buffer" in browser context * revise readme
36 lines
955 B
TypeScript
36 lines
955 B
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import {onnx} from 'onnx-proto';
|
|
|
|
import {Graph} from './graph';
|
|
import {OpSet} from './opset';
|
|
import {LongUtil} from './util';
|
|
|
|
export class Model {
|
|
// empty model
|
|
constructor() {}
|
|
|
|
load(buf: Uint8Array, graphInitializer?: Graph.Initializer): void {
|
|
const modelProto = onnx.ModelProto.decode(buf);
|
|
const irVersion = LongUtil.longToNumber(modelProto.irVersion);
|
|
if (irVersion < 3) {
|
|
throw new Error('only support ONNX model with IR_VERSION>=3');
|
|
}
|
|
|
|
this._opsets =
|
|
modelProto.opsetImport.map(i => ({domain: i.domain as string, version: LongUtil.longToNumber(i.version!)}));
|
|
|
|
this._graph = Graph.from(modelProto.graph!, graphInitializer);
|
|
}
|
|
|
|
private _graph: Graph;
|
|
get graph(): Graph {
|
|
return this._graph;
|
|
}
|
|
|
|
private _opsets: OpSet[];
|
|
get opsets(): readonly OpSet[] {
|
|
return this._opsets;
|
|
}
|
|
}
|