diff --git a/src/caffe2.js b/src/caffe2.js index 309460d079..355856388d 100644 --- a/src/caffe2.js +++ b/src/caffe2.js @@ -197,6 +197,10 @@ caffe2.Graph = class { get operators() { return this._operators; } + + toString() { + return 'graph(' + this.name + ')'; + } }; caffe2.Argument = class { @@ -327,10 +331,12 @@ caffe2.Attribute = class { this._value = arg.ints; } else if (arg.nets && arg.nets.length > 0) { - this._value = () => '{ NefDef[] }'; + this._value = arg.nets.map((net) => new caffe2.Graph(net, null)); + this._type = 'graph[]'; } else if (arg.n) { - this._value = () => '{ NefDef }'; + this._value = new caffe2.Graph(arg.n, null); + this._type = 'graph'; } else if (arg.i != 0) { this._value = arg.i; diff --git a/src/onnx.js b/src/onnx.js index 7e95bcfa12..cbc03759eb 100644 --- a/src/onnx.js +++ b/src/onnx.js @@ -328,6 +328,10 @@ onnx.Graph = class { return this._metadata; } + toString() { + return 'graph(' + this.name + ')'; + } + _connection(connections, id, type, doc_string, initializer) { var connection = connections[id]; if (!connection) { @@ -518,6 +522,9 @@ onnx.Attribute = class { constructor(metadata, operator, attribute) { this._name = attribute.name; + this._type = null; + this._value = null; + if (attribute.doc_string) { this._description = this._attribute.doc_string; } @@ -525,7 +532,6 @@ onnx.Attribute = class { this._tensor = true; } - this._value = null; if (attribute.ints && attribute.ints.length > 0) { if (attribute.ints.length > 65536) { this._value = () => '...'; @@ -557,6 +563,10 @@ onnx.Attribute = class { }); } } + else if (attribute.graphs && attribute.graphs.length > 0) { + this._value = arg.graphs.map((graph) => new onnx.Graph(metadata, graph)); + this._type = 'graph[]'; + } else if (attribute.s && attribute.s.length > 0) { if (attribute.s.filter(c => c <= 32 && c >= 128).length == 0) { this._value = String.fromCharCode.apply(null, attribute.s); @@ -574,33 +584,36 @@ onnx.Attribute = class { else if (attribute.hasOwnProperty('t')) { this._value = new onnx.Tensor(attribute.t).value; } + else if (attribute.hasOwnProperty('g')) { + this._type = 'graph'; + this._value = new onnx.Graph(metadata, attribute.g); + } var attributeSchema = metadata.getAttributeSchema(operator, attribute.name); - if (attribute.hasOwnProperty('type')) { - if (!onnx.Attribute._attributeTypeMap) { - var map = {}; - map[onnx.proto.AttributeProto.AttributeType.UNDEFINED] = 'undefined'; - map[onnx.proto.AttributeProto.AttributeType.FLOAT] = 'float'; - map[onnx.proto.AttributeProto.AttributeType.INT] = 'int'; - map[onnx.proto.AttributeProto.AttributeType.STRING] = 'string'; - map[onnx.proto.AttributeProto.AttributeType.TENSOR] = 'tensor'; - map[onnx.proto.AttributeProto.AttributeType.GRAPH] = 'graph'; - map[onnx.proto.AttributeProto.AttributeType.FLOATS] = 'float'; - map[onnx.proto.AttributeProto.AttributeType.INTS] = 'int[]'; - map[onnx.proto.AttributeProto.AttributeType.STRINGS] = 'string[]'; - map[onnx.proto.AttributeProto.AttributeType.TENSORS] = 'tensor[]'; - map[onnx.proto.AttributeProto.AttributeType.GRAPHS] = 'graph[]'; - onnx.Attribute._attributeTypeMap = map; + if (!this._type) { + if (attribute.hasOwnProperty('type')) { + if (!onnx.Attribute._attributeTypeMap) { + var map = {}; + map[onnx.proto.AttributeProto.AttributeType.UNDEFINED] = 'undefined'; + map[onnx.proto.AttributeProto.AttributeType.FLOAT] = 'float'; + map[onnx.proto.AttributeProto.AttributeType.INT] = 'int'; + map[onnx.proto.AttributeProto.AttributeType.STRING] = 'string'; + map[onnx.proto.AttributeProto.AttributeType.TENSOR] = 'tensor'; + map[onnx.proto.AttributeProto.AttributeType.GRAPH] = 'graph'; + map[onnx.proto.AttributeProto.AttributeType.FLOATS] = 'float'; + map[onnx.proto.AttributeProto.AttributeType.INTS] = 'int[]'; + map[onnx.proto.AttributeProto.AttributeType.STRINGS] = 'string[]'; + map[onnx.proto.AttributeProto.AttributeType.TENSORS] = 'tensor[]'; + map[onnx.proto.AttributeProto.AttributeType.GRAPHS] = 'graph[]'; + onnx.Attribute._attributeTypeMap = map; + } + var attributeType = onnx.Attribute._attributeTypeMap[attribute.type]; + this._type = attributeType || onnx.Attribute._attributeTypeMap[onnx.proto.AttributeProto.AttributeType.UNDEFINED]; + } + else if (attributeSchema && attributeSchema.type) { + this._type = attributeSchema.type; } - var attributeType = onnx.Attribute._attributeTypeMap[attribute.type]; - this._type = attributeType || onnx.Attribute._attributeTypeMap[onnx.proto.AttributeProto.AttributeType.UNDEFINED]; - } - else if (attributeSchema && attributeSchema.type) { - this._type = attributeSchema.type; - } - else { - this._type = null; } if (attributeSchema && attributeSchema.hasOwnProperty('default') && attributeSchema.default) { diff --git a/src/view-sidebar.js b/src/view-sidebar.js index 4316a14bcb..ecc193e2f0 100644 --- a/src/view-sidebar.js +++ b/src/view-sidebar.js @@ -296,6 +296,7 @@ class NodeAttributeView { if (value && value.length > 1000) { value = value.substring(0, 1000) + '...'; } + value = value.split('<').join('<').split('>').join('>'); var valueLine = document.createElement('div'); valueLine.className = 'sidebar-view-item-value-line'; valueLine.innerHTML = (value ? value : ' '); diff --git a/src/view.js b/src/view.js index 8a02b3d891..032d4f212c 100644 --- a/src/view.js +++ b/src/view.js @@ -857,6 +857,12 @@ view.View = class { if (type == 'shape[]') { return value.map((item) => item.toString()).join(', '); } + if (type == 'graph') { + return value.toString(); + } + if (type == 'graph[]') { + return value.map((item) => item.toString()).join(', '); + } if (Array.isArray(value)) { return value.map((item) => { if (item && item.__isLong__) {