From d5e7a79fbde52ca3ca4a8938596828f61134b4b3 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Sun, 31 Dec 2023 13:57:55 -0800 Subject: [PATCH] Update view.js --- source/circle.js | 6 +++--- source/coreml.js | 6 +++--- source/dlc.js | 7 ++----- source/hailo.js | 4 ++-- source/mxnet.js | 6 +++--- source/onnx.js | 12 ++++++------ source/rknn.js | 2 +- source/tflite.js | 4 ++-- source/view.js | 4 ++-- test/worker.js | 3 +++ 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/source/circle.js b/source/circle.js index 8b9ade0c301..56187552b04 100644 --- a/source/circle.js +++ b/source/circle.js @@ -73,7 +73,7 @@ circle.Model = class { this._format = 'Circle'; this._format = this._format + ' v' + model.version.toString(); this._description = model.description || ''; - this._metadata = []; + this._metadata = new Map(); const builtinOperators = new Map(); const upperCase = new Set([ '2D', 'LSH', 'SVDF', 'RNN', 'L2', 'LSTM' ]); for (const key of Object.keys(circle.schema.BuiltinOperator)) { @@ -114,10 +114,10 @@ circle.Model = class { this._description = this._description ? [ this._description, modelMetadata.description].join(' ') : modelMetadata.description; } if (modelMetadata.author) { - this._metadata.push({ name: 'author', value: modelMetadata.author }); + this._metadata.set('author', modelMetadata.author); } if (modelMetadata.license) { - this._metadata.push({ name: 'license', value: modelMetadata.license }); + this._metadata.set('license', modelMetadata.license); } } break; diff --git a/source/coreml.js b/source/coreml.js index d7381e89454..a5a443101a2 100644 --- a/source/coreml.js +++ b/source/coreml.js @@ -191,7 +191,7 @@ coreml.Model = class { constructor(metadata, format, model, weights) { this.format = (format || 'Core ML') + ' v' + model.specificationVersion.toString(); - this.metadata = []; + this.metadata = new Map(); const context = new coreml.Context(metadata, model, weights); const graph = new coreml.Graph(context); this.graphs = [ graph ]; @@ -204,10 +204,10 @@ coreml.Model = class { this.description = properties.shortDescription; } if (properties.author) { - this.metadata.push({ name: 'author', value: properties.author }); + this.metadata.set('author', properties.author); } if (properties.license) { - this.metadata.push({ name: 'license', value: properties.license }); + this.metadata.set('license', properties.license); } if (metadata.userDefined && Object.keys(properties.userDefined).length > 0) { /* empty */ diff --git a/source/dlc.js b/source/dlc.js index adf72302448..1598c7fcc36 100644 --- a/source/dlc.js +++ b/source/dlc.js @@ -23,7 +23,7 @@ dlc.Model = class { constructor(metadata, target) { this.format = target.format; - this.metadata = []; + this.metadata = new Map(); if (target.metadata.size > 0) { const version = target.metadata.get('model-version'); if (version) { @@ -34,10 +34,7 @@ dlc.Model = class { const source = converter.split(' ').shift().trim(); if (source.length > 0) { const version = target.metadata.get('converter-version'); - this.metadata.push({ - name: 'source', - value: version ? source + ' v' + version : source - }); + this.metadata.set('source', version ? source + ' v' + version : source); } } } diff --git a/source/hailo.js b/source/hailo.js index f4c90e32cf1..31b1e2470ce 100644 --- a/source/hailo.js +++ b/source/hailo.js @@ -22,9 +22,9 @@ hailo.Model = class { this.graphs = [ new hailo.Graph(metadata, configuration, container.weights) ]; this.name = configuration && configuration.name || ""; this.format = container.format + (container.metadata && container.metadata.sdk_version ? ' v' + container.metadata.sdk_version : ''); - this.metadata = []; + this.metadata = new Map(); if (container.metadata && container.metadata.state) { - this.metadata.push({ name: 'state', value: container.metadata.state }); + this.metadata.set('state', container.metadata.state); } } }; diff --git a/source/mxnet.js b/source/mxnet.js index 08c737cc30a..3b756814c3d 100644 --- a/source/mxnet.js +++ b/source/mxnet.js @@ -252,12 +252,12 @@ mxnet.Model = class { this._version = manifest.version; this._description = manifest.description || ''; this._runtime = manifest.runtime || ''; - this._metadata = []; + this._metadata = new Map(); if (manifest.author) { - this._metadata.push({ name: 'author', value: manifest.author }); + this._metadata.set('author', manifest.author); } if (manifest.license) { - this._metadata.push({ name: 'license', value: manifest.license }); + this._metadata.set('license', manifest.license); } this._graphs = [ new mxnet.Graph(metadata, manifest, symbol, params) ]; } diff --git a/source/onnx.js b/source/onnx.js index 4a849202d91..82742f5bdb5 100644 --- a/source/onnx.js +++ b/source/onnx.js @@ -115,7 +115,7 @@ onnx.Model = class { const model_version = model.model_version === undefined || typeof model.model_version === 'number' ? model.model_version : model.model_version.toNumber(); this._version = model_version ? model_version.toString() : ''; this._description = model.doc_string; - this._metadata = []; + this._metadata = new Map(); this._imports = null; const imports = new Map(); if (model.opset_import && model.opset_import.length > 0) { @@ -138,15 +138,15 @@ onnx.Model = class { const metadata = new Map(metadata_props.map((entry) => [ entry.key, entry.value ])); const converted_from = metadata.get('converted_from'); if (converted_from) { - this._metadata.push({ name: 'source', value: converted_from }); + this._metadata.set('source', converted_from); } const author = metadata.get('author'); if (author) { - this._metadata.push({ name: 'author', value: author }); + this._metadata.set('author', author); } const company = metadata.get('company'); if (company) { - this._metadata.push({ name: 'company', value: company }); + this._metadata.set('company', company); } let license = metadata.get('license'); const license_url = metadata.get('license_url'); @@ -154,7 +154,7 @@ onnx.Model = class { license = '' + (license ? license : license_url) + ''; } if (license) { - this._metadata.push({ name: 'license', value: license }); + this._metadata.set('license', license); } metadata.delete('author'); metadata.delete('company'); @@ -170,7 +170,7 @@ onnx.Model = class { imageMetadata[name] = value; break; default: - this._metadata.push({ name: name, value: value }); + this._metadata.set(name, value); break; } } diff --git a/source/rknn.js b/source/rknn.js index c852e73124b..fba6658846c 100644 --- a/source/rknn.js +++ b/source/rknn.js @@ -57,7 +57,7 @@ rknn.Model = class { this._name = model.name || ''; this._graphs = model.graphs.map((graph) => new rknn.Graph(metadata, type, '', graph, null)); this._metadata = []; - this._metadata.push({ name: 'source', value: model.source }); + this._metadata.set('source', model.source); break; } case 'openvx': { diff --git a/source/tflite.js b/source/tflite.js index 49565187439..5fcf5fcba91 100644 --- a/source/tflite.js +++ b/source/tflite.js @@ -127,10 +127,10 @@ tflite.Model = class { this._description = this._description ? [ this._description, modelMetadata.description].join(' ') : modelMetadata.description; } if (modelMetadata.author) { - this._metadata.push({ name: 'author', value: modelMetadata.author }); + this._metadata.set('author', modelMetadata.author); } if (modelMetadata.license) { - this._metadata.push({ name: 'license', value: modelMetadata.license }); + this._metadata.set('license', modelMetadata.license); } } break; diff --git a/source/view.js b/source/view.js index 2d7c277181b..8695c10264e 100644 --- a/source/view.js +++ b/source/view.js @@ -2959,8 +2959,8 @@ view.ModelSidebar = class extends view.ObjectSidebar { this.addProperty('runtime', model.runtime); } if (model.metadata) { - for (const entry of model.metadata) { - this.addProperty(entry.name, entry.value); + for (const [name, value] of Array.from(model.metadata)) { + this.addProperty(name, value); } } const graphs = Array.isArray(model.graphs) ? model.graphs : []; diff --git a/test/worker.js b/test/worker.js index e0bbb022c48..fa030712c55 100755 --- a/test/worker.js +++ b/test/worker.js @@ -515,6 +515,9 @@ export class Target { if (this.runtime && this.model.runtime != this.runtime) { throw new Error("Invalid runtime '" + this.model.runtime + "'."); } + if (this.model.metadata && !(this.model.metadata instanceof Map)) { + throw new Error("Invalid metadata.'"); + } if (this.assert) { for (const assert of this.assert) { const parts = assert.split('==').map((item) => item.trim());