Skip to content

Commit

Permalink
Update view.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Dec 31, 2023
1 parent bce23f3 commit d5e7a79
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions source/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions source/coreml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand All @@ -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 */
Expand Down
7 changes: 2 additions & 5 deletions source/dlc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/hailo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions source/mxnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ];
}
Expand Down
12 changes: 6 additions & 6 deletions source/onnx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -138,23 +138,23 @@ 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');
if (license_url) {
license = '<a href=\'' + license_url + '\'>' + (license ? license : license_url) + '</a>';
}
if (license) {
this._metadata.push({ name: 'license', value: license });
this._metadata.set('license', license);
}
metadata.delete('author');
metadata.delete('company');
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/rknn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
4 changes: 2 additions & 2 deletions source/tflite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : [];
Expand Down
3 changes: 3 additions & 0 deletions test/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d5e7a79

Please sign in to comment.