UNPKG

onnxruntime-web

Version:

A Javascript library for running ONNX models on browsers

1,270 lines (1,209 loc) 303 kB
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ 'use strict'; var $protobuf = require('protobufjs/minimal'); // Common aliases var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; // Exported root namespace var $root = $protobuf.roots['default'] || ($protobuf.roots['default'] = {}); $root.onnx = (function () { /** * Namespace onnx. * @exports onnx * @namespace */ var onnx = {}; /** * Version enum. * @name onnx.Version * @enum {number} * @property {number} _START_VERSION=0 _START_VERSION value * @property {number} IR_VERSION_2017_10_10=1 IR_VERSION_2017_10_10 value * @property {number} IR_VERSION_2017_10_30=2 IR_VERSION_2017_10_30 value * @property {number} IR_VERSION_2017_11_3=3 IR_VERSION_2017_11_3 value * @property {number} IR_VERSION_2019_1_22=4 IR_VERSION_2019_1_22 value * @property {number} IR_VERSION_2019_3_18=5 IR_VERSION_2019_3_18 value * @property {number} IR_VERSION_2019_9_19=6 IR_VERSION_2019_9_19 value * @property {number} IR_VERSION_2020_5_8=7 IR_VERSION_2020_5_8 value * @property {number} IR_VERSION_2021_7_30=8 IR_VERSION_2021_7_30 value * @property {number} IR_VERSION=9 IR_VERSION value */ onnx.Version = (function () { var valuesById = {}, values = Object.create(valuesById); values[(valuesById[0] = '_START_VERSION')] = 0; values[(valuesById[1] = 'IR_VERSION_2017_10_10')] = 1; values[(valuesById[2] = 'IR_VERSION_2017_10_30')] = 2; values[(valuesById[3] = 'IR_VERSION_2017_11_3')] = 3; values[(valuesById[4] = 'IR_VERSION_2019_1_22')] = 4; values[(valuesById[5] = 'IR_VERSION_2019_3_18')] = 5; values[(valuesById[6] = 'IR_VERSION_2019_9_19')] = 6; values[(valuesById[7] = 'IR_VERSION_2020_5_8')] = 7; values[(valuesById[8] = 'IR_VERSION_2021_7_30')] = 8; values[(valuesById[9] = 'IR_VERSION')] = 9; return values; })(); onnx.AttributeProto = (function () { /** * Properties of an AttributeProto. * @memberof onnx * @interface IAttributeProto * @property {string|null} [name] AttributeProto name * @property {string|null} [refAttrName] AttributeProto refAttrName * @property {string|null} [docString] AttributeProto docString * @property {onnx.AttributeProto.AttributeType|null} [type] AttributeProto type * @property {number|null} [f] AttributeProto f * @property {number|Long|null} [i] AttributeProto i * @property {Uint8Array|null} [s] AttributeProto s * @property {onnx.ITensorProto|null} [t] AttributeProto t * @property {onnx.IGraphProto|null} [g] AttributeProto g * @property {onnx.ISparseTensorProto|null} [sparseTensor] AttributeProto sparseTensor * @property {onnx.ITypeProto|null} [tp] AttributeProto tp * @property {Array.<number>|null} [floats] AttributeProto floats * @property {Array.<number|Long>|null} [ints] AttributeProto ints * @property {Array.<Uint8Array>|null} [strings] AttributeProto strings * @property {Array.<onnx.ITensorProto>|null} [tensors] AttributeProto tensors * @property {Array.<onnx.IGraphProto>|null} [graphs] AttributeProto graphs * @property {Array.<onnx.ISparseTensorProto>|null} [sparseTensors] AttributeProto sparseTensors * @property {Array.<onnx.ITypeProto>|null} [typeProtos] AttributeProto typeProtos */ /** * Constructs a new AttributeProto. * @memberof onnx * @classdesc Represents an AttributeProto. * @implements IAttributeProto * @constructor * @param {onnx.IAttributeProto=} [properties] Properties to set */ function AttributeProto(properties) { this.floats = []; this.ints = []; this.strings = []; this.tensors = []; this.graphs = []; this.sparseTensors = []; this.typeProtos = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * AttributeProto name. * @member {string} name * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.name = ''; /** * AttributeProto refAttrName. * @member {string} refAttrName * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.refAttrName = ''; /** * AttributeProto docString. * @member {string} docString * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.docString = ''; /** * AttributeProto type. * @member {onnx.AttributeProto.AttributeType} type * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.type = 0; /** * AttributeProto f. * @member {number} f * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.f = 0; /** * AttributeProto i. * @member {number|Long} i * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.i = $util.Long ? $util.Long.fromBits(0, 0, false) : 0; /** * AttributeProto s. * @member {Uint8Array} s * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.s = $util.newBuffer([]); /** * AttributeProto t. * @member {onnx.ITensorProto|null|undefined} t * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.t = null; /** * AttributeProto g. * @member {onnx.IGraphProto|null|undefined} g * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.g = null; /** * AttributeProto sparseTensor. * @member {onnx.ISparseTensorProto|null|undefined} sparseTensor * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.sparseTensor = null; /** * AttributeProto tp. * @member {onnx.ITypeProto|null|undefined} tp * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.tp = null; /** * AttributeProto floats. * @member {Array.<number>} floats * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.floats = $util.emptyArray; /** * AttributeProto ints. * @member {Array.<number|Long>} ints * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.ints = $util.emptyArray; /** * AttributeProto strings. * @member {Array.<Uint8Array>} strings * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.strings = $util.emptyArray; /** * AttributeProto tensors. * @member {Array.<onnx.ITensorProto>} tensors * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.tensors = $util.emptyArray; /** * AttributeProto graphs. * @member {Array.<onnx.IGraphProto>} graphs * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.graphs = $util.emptyArray; /** * AttributeProto sparseTensors. * @member {Array.<onnx.ISparseTensorProto>} sparseTensors * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.sparseTensors = $util.emptyArray; /** * AttributeProto typeProtos. * @member {Array.<onnx.ITypeProto>} typeProtos * @memberof onnx.AttributeProto * @instance */ AttributeProto.prototype.typeProtos = $util.emptyArray; /** * Creates a new AttributeProto instance using the specified properties. * @function create * @memberof onnx.AttributeProto * @static * @param {onnx.IAttributeProto=} [properties] Properties to set * @returns {onnx.AttributeProto} AttributeProto instance */ AttributeProto.create = function create(properties) { return new AttributeProto(properties); }; /** * Encodes the specified AttributeProto message. Does not implicitly {@link onnx.AttributeProto.verify|verify} messages. * @function encode * @memberof onnx.AttributeProto * @static * @param {onnx.IAttributeProto} message AttributeProto message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ AttributeProto.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.name != null && Object.hasOwnProperty.call(message, 'name')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.name); if (message.f != null && Object.hasOwnProperty.call(message, 'f')) writer.uint32(/* id 2, wireType 5 =*/ 21).float(message.f); if (message.i != null && Object.hasOwnProperty.call(message, 'i')) writer.uint32(/* id 3, wireType 0 =*/ 24).int64(message.i); if (message.s != null && Object.hasOwnProperty.call(message, 's')) writer.uint32(/* id 4, wireType 2 =*/ 34).bytes(message.s); if (message.t != null && Object.hasOwnProperty.call(message, 't')) $root.onnx.TensorProto.encode(message.t, writer.uint32(/* id 5, wireType 2 =*/ 42).fork()).ldelim(); if (message.g != null && Object.hasOwnProperty.call(message, 'g')) $root.onnx.GraphProto.encode(message.g, writer.uint32(/* id 6, wireType 2 =*/ 50).fork()).ldelim(); if (message.floats != null && message.floats.length) { writer.uint32(/* id 7, wireType 2 =*/ 58).fork(); for (var i = 0; i < message.floats.length; ++i) writer.float(message.floats[i]); writer.ldelim(); } if (message.ints != null && message.ints.length) { writer.uint32(/* id 8, wireType 2 =*/ 66).fork(); for (var i = 0; i < message.ints.length; ++i) writer.int64(message.ints[i]); writer.ldelim(); } if (message.strings != null && message.strings.length) for (var i = 0; i < message.strings.length; ++i) writer.uint32(/* id 9, wireType 2 =*/ 74).bytes(message.strings[i]); if (message.tensors != null && message.tensors.length) for (var i = 0; i < message.tensors.length; ++i) $root.onnx.TensorProto.encode(message.tensors[i], writer.uint32(/* id 10, wireType 2 =*/ 82).fork()).ldelim(); if (message.graphs != null && message.graphs.length) for (var i = 0; i < message.graphs.length; ++i) $root.onnx.GraphProto.encode(message.graphs[i], writer.uint32(/* id 11, wireType 2 =*/ 90).fork()).ldelim(); if (message.docString != null && Object.hasOwnProperty.call(message, 'docString')) writer.uint32(/* id 13, wireType 2 =*/ 106).string(message.docString); if (message.tp != null && Object.hasOwnProperty.call(message, 'tp')) $root.onnx.TypeProto.encode(message.tp, writer.uint32(/* id 14, wireType 2 =*/ 114).fork()).ldelim(); if (message.typeProtos != null && message.typeProtos.length) for (var i = 0; i < message.typeProtos.length; ++i) $root.onnx.TypeProto.encode( message.typeProtos[i], writer.uint32(/* id 15, wireType 2 =*/ 122).fork(), ).ldelim(); if (message.type != null && Object.hasOwnProperty.call(message, 'type')) writer.uint32(/* id 20, wireType 0 =*/ 160).int32(message.type); if (message.refAttrName != null && Object.hasOwnProperty.call(message, 'refAttrName')) writer.uint32(/* id 21, wireType 2 =*/ 170).string(message.refAttrName); if (message.sparseTensor != null && Object.hasOwnProperty.call(message, 'sparseTensor')) $root.onnx.SparseTensorProto.encode( message.sparseTensor, writer.uint32(/* id 22, wireType 2 =*/ 178).fork(), ).ldelim(); if (message.sparseTensors != null && message.sparseTensors.length) for (var i = 0; i < message.sparseTensors.length; ++i) $root.onnx.SparseTensorProto.encode( message.sparseTensors[i], writer.uint32(/* id 23, wireType 2 =*/ 186).fork(), ).ldelim(); return writer; }; /** * Encodes the specified AttributeProto message, length delimited. Does not implicitly {@link onnx.AttributeProto.verify|verify} messages. * @function encodeDelimited * @memberof onnx.AttributeProto * @static * @param {onnx.IAttributeProto} message AttributeProto message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ AttributeProto.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes an AttributeProto message from the specified reader or buffer. * @function decode * @memberof onnx.AttributeProto * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {onnx.AttributeProto} AttributeProto * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ AttributeProto.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.AttributeProto(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: { message.name = reader.string(); break; } case 21: { message.refAttrName = reader.string(); break; } case 13: { message.docString = reader.string(); break; } case 20: { message.type = reader.int32(); break; } case 2: { message.f = reader.float(); break; } case 3: { message.i = reader.int64(); break; } case 4: { message.s = reader.bytes(); break; } case 5: { message.t = $root.onnx.TensorProto.decode(reader, reader.uint32()); break; } case 6: { message.g = $root.onnx.GraphProto.decode(reader, reader.uint32()); break; } case 22: { message.sparseTensor = $root.onnx.SparseTensorProto.decode(reader, reader.uint32()); break; } case 14: { message.tp = $root.onnx.TypeProto.decode(reader, reader.uint32()); break; } case 7: { if (!(message.floats && message.floats.length)) message.floats = []; if ((tag & 7) === 2) { var end2 = reader.uint32() + reader.pos; while (reader.pos < end2) message.floats.push(reader.float()); } else message.floats.push(reader.float()); break; } case 8: { if (!(message.ints && message.ints.length)) message.ints = []; if ((tag & 7) === 2) { var end2 = reader.uint32() + reader.pos; while (reader.pos < end2) message.ints.push(reader.int64()); } else message.ints.push(reader.int64()); break; } case 9: { if (!(message.strings && message.strings.length)) message.strings = []; message.strings.push(reader.bytes()); break; } case 10: { if (!(message.tensors && message.tensors.length)) message.tensors = []; message.tensors.push($root.onnx.TensorProto.decode(reader, reader.uint32())); break; } case 11: { if (!(message.graphs && message.graphs.length)) message.graphs = []; message.graphs.push($root.onnx.GraphProto.decode(reader, reader.uint32())); break; } case 23: { if (!(message.sparseTensors && message.sparseTensors.length)) message.sparseTensors = []; message.sparseTensors.push($root.onnx.SparseTensorProto.decode(reader, reader.uint32())); break; } case 15: { if (!(message.typeProtos && message.typeProtos.length)) message.typeProtos = []; message.typeProtos.push($root.onnx.TypeProto.decode(reader, reader.uint32())); break; } default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes an AttributeProto message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof onnx.AttributeProto * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {onnx.AttributeProto} AttributeProto * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ AttributeProto.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies an AttributeProto message. * @function verify * @memberof onnx.AttributeProto * @static * @param {Object.<string,*>} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ AttributeProto.verify = function verify(message) { if (typeof message !== 'object' || message === null) return 'object expected'; if (message.name != null && message.hasOwnProperty('name')) if (!$util.isString(message.name)) return 'name: string expected'; if (message.refAttrName != null && message.hasOwnProperty('refAttrName')) if (!$util.isString(message.refAttrName)) return 'refAttrName: string expected'; if (message.docString != null && message.hasOwnProperty('docString')) if (!$util.isString(message.docString)) return 'docString: string expected'; if (message.type != null && message.hasOwnProperty('type')) switch (message.type) { default: return 'type: enum value expected'; case 0: case 1: case 2: case 3: case 4: case 5: case 11: case 13: case 6: case 7: case 8: case 9: case 10: case 12: case 14: break; } if (message.f != null && message.hasOwnProperty('f')) if (typeof message.f !== 'number') return 'f: number expected'; if (message.i != null && message.hasOwnProperty('i')) if ( !$util.isInteger(message.i) && !(message.i && $util.isInteger(message.i.low) && $util.isInteger(message.i.high)) ) return 'i: integer|Long expected'; if (message.s != null && message.hasOwnProperty('s')) if (!((message.s && typeof message.s.length === 'number') || $util.isString(message.s))) return 's: buffer expected'; if (message.t != null && message.hasOwnProperty('t')) { var error = $root.onnx.TensorProto.verify(message.t); if (error) return 't.' + error; } if (message.g != null && message.hasOwnProperty('g')) { var error = $root.onnx.GraphProto.verify(message.g); if (error) return 'g.' + error; } if (message.sparseTensor != null && message.hasOwnProperty('sparseTensor')) { var error = $root.onnx.SparseTensorProto.verify(message.sparseTensor); if (error) return 'sparseTensor.' + error; } if (message.tp != null && message.hasOwnProperty('tp')) { var error = $root.onnx.TypeProto.verify(message.tp); if (error) return 'tp.' + error; } if (message.floats != null && message.hasOwnProperty('floats')) { if (!Array.isArray(message.floats)) return 'floats: array expected'; for (var i = 0; i < message.floats.length; ++i) if (typeof message.floats[i] !== 'number') return 'floats: number[] expected'; } if (message.ints != null && message.hasOwnProperty('ints')) { if (!Array.isArray(message.ints)) return 'ints: array expected'; for (var i = 0; i < message.ints.length; ++i) if ( !$util.isInteger(message.ints[i]) && !(message.ints[i] && $util.isInteger(message.ints[i].low) && $util.isInteger(message.ints[i].high)) ) return 'ints: integer|Long[] expected'; } if (message.strings != null && message.hasOwnProperty('strings')) { if (!Array.isArray(message.strings)) return 'strings: array expected'; for (var i = 0; i < message.strings.length; ++i) if ( !( (message.strings[i] && typeof message.strings[i].length === 'number') || $util.isString(message.strings[i]) ) ) return 'strings: buffer[] expected'; } if (message.tensors != null && message.hasOwnProperty('tensors')) { if (!Array.isArray(message.tensors)) return 'tensors: array expected'; for (var i = 0; i < message.tensors.length; ++i) { var error = $root.onnx.TensorProto.verify(message.tensors[i]); if (error) return 'tensors.' + error; } } if (message.graphs != null && message.hasOwnProperty('graphs')) { if (!Array.isArray(message.graphs)) return 'graphs: array expected'; for (var i = 0; i < message.graphs.length; ++i) { var error = $root.onnx.GraphProto.verify(message.graphs[i]); if (error) return 'graphs.' + error; } } if (message.sparseTensors != null && message.hasOwnProperty('sparseTensors')) { if (!Array.isArray(message.sparseTensors)) return 'sparseTensors: array expected'; for (var i = 0; i < message.sparseTensors.length; ++i) { var error = $root.onnx.SparseTensorProto.verify(message.sparseTensors[i]); if (error) return 'sparseTensors.' + error; } } if (message.typeProtos != null && message.hasOwnProperty('typeProtos')) { if (!Array.isArray(message.typeProtos)) return 'typeProtos: array expected'; for (var i = 0; i < message.typeProtos.length; ++i) { var error = $root.onnx.TypeProto.verify(message.typeProtos[i]); if (error) return 'typeProtos.' + error; } } return null; }; /** * Creates an AttributeProto message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof onnx.AttributeProto * @static * @param {Object.<string,*>} object Plain object * @returns {onnx.AttributeProto} AttributeProto */ AttributeProto.fromObject = function fromObject(object) { if (object instanceof $root.onnx.AttributeProto) return object; var message = new $root.onnx.AttributeProto(); if (object.name != null) message.name = String(object.name); if (object.refAttrName != null) message.refAttrName = String(object.refAttrName); if (object.docString != null) message.docString = String(object.docString); switch (object.type) { default: if (typeof object.type === 'number') { message.type = object.type; break; } break; case 'UNDEFINED': case 0: message.type = 0; break; case 'FLOAT': case 1: message.type = 1; break; case 'INT': case 2: message.type = 2; break; case 'STRING': case 3: message.type = 3; break; case 'TENSOR': case 4: message.type = 4; break; case 'GRAPH': case 5: message.type = 5; break; case 'SPARSE_TENSOR': case 11: message.type = 11; break; case 'TYPE_PROTO': case 13: message.type = 13; break; case 'FLOATS': case 6: message.type = 6; break; case 'INTS': case 7: message.type = 7; break; case 'STRINGS': case 8: message.type = 8; break; case 'TENSORS': case 9: message.type = 9; break; case 'GRAPHS': case 10: message.type = 10; break; case 'SPARSE_TENSORS': case 12: message.type = 12; break; case 'TYPE_PROTOS': case 14: message.type = 14; break; } if (object.f != null) message.f = Number(object.f); if (object.i != null) if ($util.Long) (message.i = $util.Long.fromValue(object.i)).unsigned = false; else if (typeof object.i === 'string') message.i = parseInt(object.i, 10); else if (typeof object.i === 'number') message.i = object.i; else if (typeof object.i === 'object') message.i = new $util.LongBits(object.i.low >>> 0, object.i.high >>> 0).toNumber(); if (object.s != null) if (typeof object.s === 'string') $util.base64.decode(object.s, (message.s = $util.newBuffer($util.base64.length(object.s))), 0); else if (object.s.length >= 0) message.s = object.s; if (object.t != null) { if (typeof object.t !== 'object') throw TypeError('.onnx.AttributeProto.t: object expected'); message.t = $root.onnx.TensorProto.fromObject(object.t); } if (object.g != null) { if (typeof object.g !== 'object') throw TypeError('.onnx.AttributeProto.g: object expected'); message.g = $root.onnx.GraphProto.fromObject(object.g); } if (object.sparseTensor != null) { if (typeof object.sparseTensor !== 'object') throw TypeError('.onnx.AttributeProto.sparseTensor: object expected'); message.sparseTensor = $root.onnx.SparseTensorProto.fromObject(object.sparseTensor); } if (object.tp != null) { if (typeof object.tp !== 'object') throw TypeError('.onnx.AttributeProto.tp: object expected'); message.tp = $root.onnx.TypeProto.fromObject(object.tp); } if (object.floats) { if (!Array.isArray(object.floats)) throw TypeError('.onnx.AttributeProto.floats: array expected'); message.floats = []; for (var i = 0; i < object.floats.length; ++i) message.floats[i] = Number(object.floats[i]); } if (object.ints) { if (!Array.isArray(object.ints)) throw TypeError('.onnx.AttributeProto.ints: array expected'); message.ints = []; for (var i = 0; i < object.ints.length; ++i) if ($util.Long) (message.ints[i] = $util.Long.fromValue(object.ints[i])).unsigned = false; else if (typeof object.ints[i] === 'string') message.ints[i] = parseInt(object.ints[i], 10); else if (typeof object.ints[i] === 'number') message.ints[i] = object.ints[i]; else if (typeof object.ints[i] === 'object') message.ints[i] = new $util.LongBits(object.ints[i].low >>> 0, object.ints[i].high >>> 0).toNumber(); } if (object.strings) { if (!Array.isArray(object.strings)) throw TypeError('.onnx.AttributeProto.strings: array expected'); message.strings = []; for (var i = 0; i < object.strings.length; ++i) if (typeof object.strings[i] === 'string') $util.base64.decode( object.strings[i], (message.strings[i] = $util.newBuffer($util.base64.length(object.strings[i]))), 0, ); else if (object.strings[i].length >= 0) message.strings[i] = object.strings[i]; } if (object.tensors) { if (!Array.isArray(object.tensors)) throw TypeError('.onnx.AttributeProto.tensors: array expected'); message.tensors = []; for (var i = 0; i < object.tensors.length; ++i) { if (typeof object.tensors[i] !== 'object') throw TypeError('.onnx.AttributeProto.tensors: object expected'); message.tensors[i] = $root.onnx.TensorProto.fromObject(object.tensors[i]); } } if (object.graphs) { if (!Array.isArray(object.graphs)) throw TypeError('.onnx.AttributeProto.graphs: array expected'); message.graphs = []; for (var i = 0; i < object.graphs.length; ++i) { if (typeof object.graphs[i] !== 'object') throw TypeError('.onnx.AttributeProto.graphs: object expected'); message.graphs[i] = $root.onnx.GraphProto.fromObject(object.graphs[i]); } } if (object.sparseTensors) { if (!Array.isArray(object.sparseTensors)) throw TypeError('.onnx.AttributeProto.sparseTensors: array expected'); message.sparseTensors = []; for (var i = 0; i < object.sparseTensors.length; ++i) { if (typeof object.sparseTensors[i] !== 'object') throw TypeError('.onnx.AttributeProto.sparseTensors: object expected'); message.sparseTensors[i] = $root.onnx.SparseTensorProto.fromObject(object.sparseTensors[i]); } } if (object.typeProtos) { if (!Array.isArray(object.typeProtos)) throw TypeError('.onnx.AttributeProto.typeProtos: array expected'); message.typeProtos = []; for (var i = 0; i < object.typeProtos.length; ++i) { if (typeof object.typeProtos[i] !== 'object') throw TypeError('.onnx.AttributeProto.typeProtos: object expected'); message.typeProtos[i] = $root.onnx.TypeProto.fromObject(object.typeProtos[i]); } } return message; }; /** * Creates a plain object from an AttributeProto message. Also converts values to other types if specified. * @function toObject * @memberof onnx.AttributeProto * @static * @param {onnx.AttributeProto} message AttributeProto * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.<string,*>} Plain object */ AttributeProto.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.arrays || options.defaults) { object.floats = []; object.ints = []; object.strings = []; object.tensors = []; object.graphs = []; object.typeProtos = []; object.sparseTensors = []; } if (options.defaults) { object.name = ''; object.f = 0; if ($util.Long) { var long = new $util.Long(0, 0, false); object.i = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; } else object.i = options.longs === String ? '0' : 0; if (options.bytes === String) object.s = ''; else { object.s = []; if (options.bytes !== Array) object.s = $util.newBuffer(object.s); } object.t = null; object.g = null; object.docString = ''; object.tp = null; object.type = options.enums === String ? 'UNDEFINED' : 0; object.refAttrName = ''; object.sparseTensor = null; } if (message.name != null && message.hasOwnProperty('name')) object.name = message.name; if (message.f != null && message.hasOwnProperty('f')) object.f = options.json && !isFinite(message.f) ? String(message.f) : message.f; if (message.i != null && message.hasOwnProperty('i')) if (typeof message.i === 'number') object.i = options.longs === String ? String(message.i) : message.i; else object.i = options.longs === String ? $util.Long.prototype.toString.call(message.i) : options.longs === Number ? new $util.LongBits(message.i.low >>> 0, message.i.high >>> 0).toNumber() : message.i; if (message.s != null && message.hasOwnProperty('s')) object.s = options.bytes === String ? $util.base64.encode(message.s, 0, message.s.length) : options.bytes === Array ? Array.prototype.slice.call(message.s) : message.s; if (message.t != null && message.hasOwnProperty('t')) object.t = $root.onnx.TensorProto.toObject(message.t, options); if (message.g != null && message.hasOwnProperty('g')) object.g = $root.onnx.GraphProto.toObject(message.g, options); if (message.floats && message.floats.length) { object.floats = []; for (var j = 0; j < message.floats.length; ++j) object.floats[j] = options.json && !isFinite(message.floats[j]) ? String(message.floats[j]) : message.floats[j]; } if (message.ints && message.ints.length) { object.ints = []; for (var j = 0; j < message.ints.length; ++j) if (typeof message.ints[j] === 'number') object.ints[j] = options.longs === String ? String(message.ints[j]) : message.ints[j]; else object.ints[j] = options.longs === String ? $util.Long.prototype.toString.call(message.ints[j]) : options.longs === Number ? new $util.LongBits(message.ints[j].low >>> 0, message.ints[j].high >>> 0).toNumber() : message.ints[j]; } if (message.strings && message.strings.length) { object.strings = []; for (var j = 0; j < message.strings.length; ++j) object.strings[j] = options.bytes === String ? $util.base64.encode(message.strings[j], 0, message.strings[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.strings[j]) : message.strings[j]; } if (message.tensors && message.tensors.length) { object.tensors = []; for (var j = 0; j < message.tensors.length; ++j) object.tensors[j] = $root.onnx.TensorProto.toObject(message.tensors[j], options); } if (message.graphs && message.graphs.length) { object.graphs = []; for (var j = 0; j < message.graphs.length; ++j) object.graphs[j] = $root.onnx.GraphProto.toObject(message.graphs[j], options); } if (message.docString != null && message.hasOwnProperty('docString')) object.docString = message.docString; if (message.tp != null && message.hasOwnProperty('tp')) object.tp = $root.onnx.TypeProto.toObject(message.tp, options); if (message.typeProtos && message.typeProtos.length) { object.typeProtos = []; for (var j = 0; j < message.typeProtos.length; ++j) object.typeProtos[j] = $root.onnx.TypeProto.toObject(message.typeProtos[j], options); } if (message.type != null && message.hasOwnProperty('type')) object.type = options.enums === String ? $root.onnx.AttributeProto.AttributeType[message.type] === undefined ? message.type : $root.onnx.AttributeProto.AttributeType[message.type] : message.type; if (message.refAttrName != null && message.hasOwnProperty('refAttrName')) object.refAttrName = message.refAttrName; if (message.sparseTensor != null && message.hasOwnProperty('sparseTensor')) object.sparseTensor = $root.onnx.SparseTensorProto.toObject(message.sparseTensor, options); if (message.sparseTensors && message.sparseTensors.length) { object.sparseTensors = []; for (var j = 0; j < message.sparseTensors.length; ++j) object.sparseTensors[j] = $root.onnx.SparseTensorProto.toObject(message.sparseTensors[j], options); } return object; }; /** * Converts this AttributeProto to JSON. * @function toJSON * @memberof onnx.AttributeProto * @instance * @returns {Object.<string,*>} JSON object */ AttributeProto.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; /** * Gets the default type url for AttributeProto * @function getTypeUrl * @memberof onnx.AttributeProto * @static * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") * @returns {string} The default type url */ AttributeProto.getTypeUrl = function getTypeUrl(typeUrlPrefix) { if (typeUrlPrefix === undefined) { typeUrlPrefix = 'type.googleapis.com'; } return typeUrlPrefix + '/onnx.AttributeProto'; }; /** * AttributeType enum. * @name onnx.AttributeProto.AttributeType * @enum {number} * @property {number} UNDEFINED=0 UNDEFINED value * @property {number} FLOAT=1 FLOAT value * @property {number} INT=2 INT value * @property {number} STRING=3 STRING value * @property {number} TENSOR=4 TENSOR value * @property {number} GRAPH=5 GRAPH value * @property {number} SPARSE_TENSOR=11 SPARSE_TENSOR value * @property {number} TYPE_PROTO=13 TYPE_PROTO value * @property {number} FLOATS=6 FLOATS value * @property {number} INTS=7 INTS value * @property {number} STRINGS=8 STRINGS value * @property {number} TENSORS=9 TENSORS value * @property {number} GRAPHS=10 GRAPHS value * @property {number} SPARSE_TENSORS=12 SPARSE_TENSORS value * @property {number} TYPE_PROTOS=14 TYPE_PROTOS value */ AttributeProto.AttributeType = (function () { var valuesById = {}, values = Object.create(valuesById); values[(valuesById[0] = 'UNDEFINED')] = 0; values[(valuesById[1] = 'FLOAT')] = 1; values[(valuesById[2] = 'INT')] = 2; values[(valuesById[3] = 'STRING')] = 3; values[(valuesById[4] = 'TENSOR')] = 4; values[(valuesById[5] = 'GRAPH')] = 5; values[(valuesById[11] = 'SPARSE_TENSOR')] = 11; values[(valuesById[13] = 'TYPE_PROTO')] = 13; values[(valuesById[6] = 'FLOATS')] = 6; values[(valuesById[7] = 'INTS')] = 7; values[(valuesById[8] = 'STRINGS')] = 8; values[(valuesById[9] = 'TENSORS')] = 9; values[(valuesById[10] = 'GRAPHS')] = 10; values[(valuesById[12] = 'SPARSE_TENSORS')] = 12; values[(valuesById[14] = 'TYPE_PROTOS')] = 14; return values; })(); return AttributeProto; })(); onnx.ValueInfoProto = (function () { /** * Properties of a ValueInfoProto. * @memberof onnx * @interface IValueInfoProto * @property {string|null} [name] ValueInfoProto name * @property {onnx.ITypeProto|null} [type] ValueInfoProto type * @property {string|null} [docString] ValueInfoProto docString */ /** * Constructs a new ValueInfoProto. * @memberof onnx * @classdesc Represents a ValueInfoProto. * @implements IValueInfoProto * @constructor * @param {onnx.IValueInfoProto=} [properties] Properties to set */ function ValueInfoProto(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * ValueInfoProto name. * @member {string} name * @memberof onnx.ValueInfoProto * @instance */ ValueInfoProto.prototype.name = ''; /** * ValueInfoProto type. * @member {onnx.ITypeProto|null|undefined} type * @memberof onnx.ValueInfoProto * @instance */ ValueInfoProto.prototype.type = null; /** * ValueInfoProto docString. * @member {string} docString * @memberof onnx.ValueInfoProto * @instance */ ValueInfoProto.prototype.docString = ''; /** * Creates a new ValueInfoProto instance using the specified properties. * @function create * @memberof onnx.ValueInfoProto * @static * @param {onnx.IValueInfoProto=} [properties] Properties to set * @returns {onnx.ValueInfoProto} ValueInfoProto instance */ ValueInfoProto.create = function create(properties) { return new ValueInfoProto(properties); }; /** * Encodes the specified ValueInfoProto message. Does not implicitly {@link onnx.ValueInfoProto.verify|verify} messages. * @function encode * @memberof onnx.ValueInfoProto * @static * @param {onnx.IValueInfoProto} message ValueInfoProto message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ ValueInfoProto.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.name != null && Object.hasOwnProperty.call(message, 'name')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.name); if (message.type != null && Object.hasOwnProperty.call(message, 'type')) $root.onnx.TypeProto.encode(message.type, writer.uint32(/* id 2, wireType 2 =*/ 18).fork()).ldelim(); if (message.docString != null && Object.hasOwnProperty.call(message, 'docString')) writer.uint32(/* id 3, wireType 2 =*/ 26).string(message.docString); return writer; }; /** * Encodes the specified ValueInfoProto message, length delimited. Does not implicitly {@link onnx.ValueInfoProto.verify|verify} messages. * @function encodeDelimited * @memberof onnx.ValueInfoProto * @static * @param {onnx.IValueInfoProto} message ValueInfoProto message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ ValueInfoProto.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a ValueInfoProto message from the specified reader or buffer. * @function decode * @memberof onnx.ValueInfoProto * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {onnx.ValueInfoProto} ValueInfoProto * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ ValueInfoProto.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.ValueInfoProto(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: { message.name = reader.string(); break; } case 2: { message.type = $root.onnx.TypeProto.decode(reader, reader.uint32()); break; } case 3: { message.docString = reader.string(); break; } default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a ValueInfoProto message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof onnx.ValueInfoProto * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {onnx.ValueInfoProto} ValueInfoProto * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ ValueInfoProto.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a ValueInfoProto message. * @function verify * @memberof onnx.ValueInfoProto * @static * @param {Object.<string,*>} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ ValueInfoProto.verify = function verify(message) { if (typeof message !== 'object' || message === null) return 'object expected'; if (message.name != null && message.hasOwnProperty('name')) if (!$util.isString(message.name)) return 'name: string expected'; if (message.type != null && message.hasOwnProperty('type')) { var error = $root.onnx.TypeProto.verify(message.type); if (error) return 'type.' + error; } if (message.docString != null && message.hasOwnProperty('docString')) if (!$util.isString(message.docString)) return 'docString: string expected'; return null; }; /** * Creates a ValueInfoProto message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof onnx.ValueInfoProto * @static * @param {Object.<string,*>} object Plain object * @returns {onnx.ValueInfoProto} ValueInfoProto */ ValueInfoProto.fromObject = function fromObject(object) { if (object instanceof $root.onnx.ValueInfoProto) return object; var message = new $root.onnx.ValueInfoProto(); if (object.name != null) message.name = String(object.name); if (object.type != null) { if (typeof object.type !== 'object') throw TypeError('.onnx.ValueInfoProto.type: object expected'); message.type = $root.onnx.TypeProto.fromObject(object.type); } if (object.docString != null) message.docString = String(object.docString); return message; }; /** * Creates a plain object from a ValueInfoProto message. Also converts values to other types if specified. * @function toObject * @memberof onnx.ValueInfoProto * @static * @param {onnx.ValueInfoProto} message ValueInfoProto * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.<string,*>} Plain object */ ValueInfoProto.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.defaults) { object.name = ''; object.type = null; object.docString = ''; } if (message.name != null && message.hasOwnProperty('name')) object.name = message.name; if (message.type != null && message.hasOwnProperty('type')) object.type = $root.onnx.TypeProto.toObject(message.type, options); if (message.docString != null && message.hasOwnProperty('docString')) object.docString = message.docString; return object; }; /** * Converts this ValueInfoProto to JSON. * @function toJSON * @memberof onnx.ValueInfoProto * @instance * @returns {Object.<string,*>} JSON object */ ValueInfoProto.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; /** * Gets the default type url for ValueInfoProto * @function getTypeUrl * @memberof onnx.ValueInfoProto * @static * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") * @returns {string} The default type url */ ValueInfoProto.getTypeUrl = function getTypeUrl(typeUrlPrefix) { if (typeUrlPrefix === undefined) { typeUrlPrefix = 'type.googleapis.com'; } return typeUrlPrefix + '/onnx.ValueInfoProto'; }; return ValueInfoProto; })(); onnx.NodeProto = (function () { /** * Properties of a NodeProto. * @memberof onnx * @interface INodeProto * @property {Array.<string>|null} [input] NodeProto input * @property {Array.<string>|null} [output] NodeProto output * @property {string|null} [name] NodeProto name * @property {string|null} [opType] NodeProto opType * @property {string|null} [domain] NodeProto domain * @property {Array.<onnx.IAttributeProto>|null} [attribute] NodeProto attribute * @property {string|null} [docString] NodeProto docString */ /** * Constructs a new NodeProto. * @memberof onnx * @classdesc Represents a NodeProto. * @implements INodeProto * @constructor * @param {onnx.INodeProto=} [properties] Properties to set */ function NodeProto(properties) { this.input = []; this.output = []; this.attribute = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * NodeProto input. * @member {Array.<string>} input * @memberof onnx.NodeProto * @instance */ NodeProto.prototype.input = $util.emptyArray; /** * NodeProto output. * @member {Array.<string>} output * @memberof onnx.NodeProto * @instance */ NodeProto.prototype.output = $util.emptyArray; /** * NodeProto name. * @member {string} name * @memberof onnx.NodeProto * @instance */ NodeProto.prototype.name = ''; /** * NodeProto opType. * @member {string} opType * @memberof onnx.NodeProto * @instance */ NodeProto.prototype.opType = ''; /** * NodeProto domain. * @member {string} domain * @memberof onnx.NodeProto * @instance */ NodeProto.prototype.domain = ''; /** *