Skip to content

Commit

Permalink
Show attribute subgraph names (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Nov 22, 2018
1 parent 43e2fb3 commit 440f909
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
10 changes: 8 additions & 2 deletions src/caffe2.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ caffe2.Graph = class {
get operators() {
return this._operators;
}

toString() {
return 'graph(' + this.name + ')';
}
};

caffe2.Argument = class {
Expand Down Expand Up @@ -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;
Expand Down
61 changes: 37 additions & 24 deletions src/onnx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -518,14 +522,16 @@ 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;
}
if (attribute.hasOwnProperty('t')) {
this._tensor = true;
}

this._value = null;
if (attribute.ints && attribute.ints.length > 0) {
if (attribute.ints.length > 65536) {
this._value = () => '...';
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/view-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class NodeAttributeView {
if (value && value.length > 1000) {
value = value.substring(0, 1000) + '...';
}
value = value.split('<').join('&lt;').split('>').join('&gt;');
var valueLine = document.createElement('div');
valueLine.className = 'sidebar-view-item-value-line';
valueLine.innerHTML = (value ? value : '&nbsp;');
Expand Down
6 changes: 6 additions & 0 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__) {
Expand Down

0 comments on commit 440f909

Please sign in to comment.