Kaynağa Gözat

Update documentation code

Lutz Roeder 6 yıl önce
ebeveyn
işleme
8110d2227c
32 değiştirilmiş dosya ile 296 ekleme ve 1506 silme
  1. 3 9
      src/armnn.js
  2. 3 8
      src/bigdl.js
  3. 3 8
      src/caffe.js
  4. 3 45
      src/caffe2.js
  5. 2 6
      src/chainer.js
  6. 3 7
      src/cntk.js
  7. 3 38
      src/coreml.js
  8. 4 46
      src/darknet.js
  9. 5 11
      src/dl4j.js
  10. 0 1
      src/flux.js
  11. 3 45
      src/keras.js
  12. 2 6
      src/mediapipe.js
  13. 3 38
      src/mlnet.js
  14. 3 7
      src/mnn.js
  15. 3 38
      src/mxnet.js
  16. 3 7
      src/ncnn.js
  17. 40 13
      src/onnx-metadata.json
  18. 5 56
      src/onnx.js
  19. 3 45
      src/openvino.js
  20. 4 10
      src/paddle.js
  21. 2 38
      src/pytorch.js
  22. 3 45
      src/sklearn.js
  23. 21 861
      src/tf-metadata.json
  24. 3 74
      src/tf.js
  25. 7 13
      src/tflite.js
  26. 4 10
      src/torch.js
  27. 1 1
      src/view-sidebar.css
  28. 51 8
      src/view-sidebar.js
  29. 5 4
      src/view.js
  30. 5 2
      test/test.js
  31. 24 4
      tools/onnx-script.py
  32. 72 2
      tools/tf-script.py

+ 3 - 9
src/armnn.js

@@ -129,7 +129,6 @@ armnn.Node = class {
         this._name = '';
         this._outputs = [];
         this._inputs = [];
-        this._category = '';
         this._attributes = [];
 
         const base = armnn.Node.getBase(layer)
@@ -150,8 +149,6 @@ armnn.Node = class {
 
         const schema = this._metadata.type(this._operator);
         if (schema) {
-            this._category = schema.category || '';
-
             const _layer = armnn.Node.castLayer(layer);
 
             if (schema.bindings) {
@@ -192,18 +189,14 @@ armnn.Node = class {
         return null;
     }
 
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get group() {
         return null;
     }
 
-    get category() {
-        return this._category;
-    }
-
     get inputs() {
         return this._inputs;
     }
@@ -577,6 +570,7 @@ armnn.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 3 - 8
src/bigdl.js

@@ -6,7 +6,6 @@
 var bigdl = bigdl || {};
 var long = long || { Long: require('long') };
 var protobuf = protobuf || require('protobufjs');
-var marked = marked || require('marked');
 
 bigdl.ModelFactory = class {
 
@@ -239,13 +238,8 @@ bigdl.Node = class {
         return this._type;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._type);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._type);
     }
 
     get name() {
@@ -455,6 +449,7 @@ bigdl.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 3 - 8
src/caffe.js

@@ -5,7 +5,6 @@ var caffe = caffe || {};
 var long = long || { Long: require('long') };
 var protobuf = protobuf || require('protobufjs');
 var prototxt = prototxt || require('protobufjs/ext/prototxt');
-var marked = marked || require('marked');
 
 caffe.ModelFactory = class {
 
@@ -553,13 +552,8 @@ caffe.Node = class {
         return this._type;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._type);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._type);
     }
 
     get name() { 
@@ -800,6 +794,7 @@ caffe.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 3 - 45
src/caffe2.js

@@ -4,7 +4,6 @@
 var caffe2 = caffe2 || {};
 var protobuf = protobuf || require('protobufjs');
 var prototxt = prototxt || require('protobufjs/ext/prototxt');
-var marked = marked || require('marked');
 
 caffe2.ModelFactory = class {
 
@@ -450,50 +449,8 @@ caffe2.Node = class {
         return this._operator;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this._operator);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (let attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (let input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (let output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            if (schema.references) {
-                for (let reference of schema.references) {
-                    if (reference) {
-                        reference.description = marked(reference.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get inputs() {
@@ -809,6 +766,7 @@ caffe2.Metadata = class {
             if (items) {
                 for (let item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 2 - 6
src/chainer.js

@@ -375,12 +375,8 @@ chainer.Node = class {
         return this._name;
     }
 
-    get category() {
-        return '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return null;
     }
 
     get inputs() {

+ 3 - 7
src/cntk.js

@@ -488,13 +488,8 @@ cntk.Node = class {
         return this._function || false;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._function ? ('Function:' + this._operator) : this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() { 
-        return '';
+    get metadata() {
+        return this._metadata.type(this._function ? ('Function:' + this._operator) : this._operator);
     }
 
     get attributes() { 
@@ -807,6 +802,7 @@ cntk.Metadata = class {
                     if (item.name && item.schema) {
                         const name = item.name;
                         const schema = item.schema;
+                        schema.name = name;
                         this._map[name] = schema;
                         if (Object.prototype.hasOwnProperty.call(schema, 'operator')) {
                             this._operatorMap[schema.operator.toString()] = name;

+ 3 - 38
src/coreml.js

@@ -5,7 +5,6 @@ var coreml = coreml || {};
 var base = base || require('./base');
 var long = long || { Long: require('long') };
 var protobuf = protobuf || require('protobufjs');
-var marked = marked || require('marked');
 
 coreml.ModelFactory = class {
 
@@ -592,43 +591,8 @@ coreml.Node = class {
         return this._name;
     }
 
-    get category() {
-        const schema = this._metadata.type(this.operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this.operator);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this.operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this.operator);
     }
 
     get group() {
@@ -1126,6 +1090,7 @@ coreml.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 4 - 46
src/darknet.js

@@ -4,7 +4,6 @@
 var darknet = darknet || {};
 var base = base || require('./base');
 var long = long || { Long: require('long') };
-var marked = marked || require('marked');
 
 darknet.ModelFactory = class {
 
@@ -715,7 +714,7 @@ darknet.Argument = class {
 darknet.Node = class {
 
     constructor(metadata, net, section) {
-        this._name = (section.name || '') + (section.line !== undefined ? '@' + section.line.toString() : '');
+        this._name = (section.name || '') + (section.line !== undefined ? '@line:' + section.line.toString() : '');
         this._metadata = metadata;
         this._operator = section.type;
         this._attributes = [];
@@ -753,50 +752,8 @@ darknet.Node = class {
         return this._operator;
     }
 
-    get documentation() {
-        let schema = this._metadata.type(this._operator);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            if (schema.references) {
-                for (const reference of schema.references) {
-                    if (reference) {
-                        reference.description = marked(reference.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
-    }
-
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get attributes() {
@@ -1063,6 +1020,7 @@ darknet.Metadata = class {
                         if (this._map.has(item.name)) {
                             throw new darknet.Error("Duplicate metadata key '" + item.name + "'.");
                         }
+                        item.schema.name = item.name;
                         this._map.set(item.name, item.schema);
                     }
                 }

+ 5 - 11
src/dl4j.js

@@ -345,13 +345,8 @@ dl4j.Node = class {
         return this._name;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get inputs() {
@@ -501,12 +496,11 @@ dl4j.Metadata = class {
         this._attributeCache = {};
         if (data) {
             if (data) {
-                let items = JSON.parse(data);
+                const items = JSON.parse(data);
                 if (items) {
                     for (const item of items) {
-                        if (item.name && item.schema) {
-                            this._map[item.name] = item.schema;
-                        }
+                        item.schema.name = item.name;
+                        this._map[item.name] = item.schema;
                     }
                 }
             }

+ 0 - 1
src/flux.js

@@ -4,7 +4,6 @@
 // Experimental
 
 var flux = flux || {};
-var marked = marked || require('marked');
 
 flux.ModelFactory = class {
 

+ 3 - 45
src/keras.js

@@ -3,7 +3,6 @@
 
 var keras = keras || {};
 var base = base || require('./base');
-var marked = marked || require('marked');
 
 keras.ModelFactory = class {
 
@@ -648,50 +647,8 @@ keras.Node = class {
         return this._group ? this._group : '';
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this._operator);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            if (schema.references) {
-                for (const reference of schema.references) {
-                    if (reference) {
-                        reference.description = marked(reference.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get inputs() {
@@ -1045,6 +1002,7 @@ keras.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 2 - 6
src/mediapipe.js

@@ -185,12 +185,8 @@ mediapipe.Node = class {
         return this._type;
     }
 
-    get documentation() {
-        return '';
-    }
-
-    get category() {
-        return '';
+    get metadata() {
+        return null;
     }
 
     get inputs() {

+ 3 - 38
src/mlnet.js

@@ -4,7 +4,6 @@
 // Experimental
 
 var mlnet = mlnet || {};
-var marked = marked || require('marked');
 var zip = zip || require('./zip');
 
 mlnet.ModelFactory = class {
@@ -236,43 +235,8 @@ mlnet.Node = class {
         return this._name;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator); 
-        return schema && schema.category ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this._operator); 
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator); 
     }
 
     get inputs() {
@@ -430,6 +394,7 @@ mlnet.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 3 - 7
src/mnn.js

@@ -328,19 +328,14 @@ mnn.Node = class {
         return null;
     }
 
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this.operator);
     }
 
     get group() {
         return null;
     }
 
-    get category() {
-        let schema = this._metadata.type(this.operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
     get inputs() {
         return this._inputs;
     }
@@ -586,6 +581,7 @@ mnn.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map.set(item.name, item.schema);
                     }
                 }

+ 3 - 38
src/mxnet.js

@@ -2,7 +2,6 @@
 /* eslint "indent": [ "error", 4, { "SwitchCase": 1 } ] */
 
 var mxnet = mxnet || {};
-var marked = marked || require('marked');
 var long = long || { Long: require('long') };
 var zip = zip || require('./zip');
 var ndarray = ndarray || {};
@@ -748,43 +747,8 @@ mxnet.Node = class {
         return this._operator;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator); 
-        return schema && schema.category ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this._operator); 
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator); 
     }
 
     get name() {
@@ -1118,6 +1082,7 @@ mxnet.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

+ 3 - 7
src/ncnn.js

@@ -473,13 +473,8 @@ ncnn.Node = class {
         return this._name;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get attributes() {
@@ -730,6 +725,7 @@ ncnn.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                         if (Object.prototype.hasOwnProperty.call(item.schema, 'operator')) {
                             this._operatorMap[item.schema.operator.toString()] = item.name;

Dosya farkı çok büyük olduğundan ihmal edildi
+ 40 - 13
src/onnx-metadata.json


+ 5 - 56
src/onnx.js

@@ -487,66 +487,14 @@ onnx.Node = class {
         return this._description;
     }
 
-    get documentation() {
-        let schema = this._metadata.type(this._operator);
-        if (schema) {
-            const options = { baseUrl: 'https://github.com/onnx/onnx/blob/master/docs/' };
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._operator;
-            if (schema.description) {
-                schema.description = marked(schema.description, options);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description, options);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description, options);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description, options);
-                    }
-                }
-            }
-            let formatRange = (value) => {
-                return (value == 2147483647) ? '∞' : value.toString();
-            };
-            if (schema.min_input != schema.max_input) {
-                schema.inputs_range = formatRange(schema.min_input) + ' - ' + formatRange(schema.max_input);
-            }
-            if (schema.min_output != schema.max_output) {
-                schema.outputs_range = formatRange(schema.min_output) + ' - ' + formatRange(schema.max_output);
-            }
-            if (schema.type_constraints) {
-                for (const type_constraint of schema.type_constraints) {
-                    if (type_constraint.allowed_type_strs) {
-                        type_constraint.allowed_type_strs_display = type_constraint.allowed_type_strs.map((type) => { return type; }).join(', ');
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get domain() {
         return this._domain;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
     get group() {
         return null;
     }
@@ -1193,11 +1141,12 @@ onnx.Metadata = class {
     constructor(data) {
         this._map = {};
         if (data) {
-            let items = JSON.parse(data);
+            const items = JSON.parse(data);
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
-                        let name = item.name;
+                        const name = item.name;
+                        item.schema.name = name;
                         this._map[name] = this._map[name] || [];
                         this._map[name].push(item.schema);
                     }

+ 3 - 45
src/openvino.js

@@ -4,7 +4,6 @@
 var openvino = openvino || {};
 var base = base || require('./base');
 var long = long || { Long: require('long') };
-var marked = marked || require('marked');
 
 openvino.ModelFactory = class {
 
@@ -515,50 +514,8 @@ openvino.Node = class {
         return this._type;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._type);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this._type);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this._type;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            if (schema.references) {
-                for (const reference of schema.references) {
-                    if (reference) {
-                        reference.description = marked(reference.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._type);
     }
 
     get attributes() {
@@ -971,6 +928,7 @@ openvino.Metadata = class {
                         if (this._map.has(item.name)) {
                             throw new openvino.Error("Duplicate metadata key '" + item.name + "'.");
                         }
+                        item.schema.name = item.name;
                         this._map.set(item.name, item.schema);
                     }
                 }

+ 4 - 10
src/paddle.js

@@ -250,13 +250,8 @@ paddle.Node = class {
         return '';
     }
 
-    get category() {
-        const schema = this._metadata.type(this._operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._operator);
     }
 
     get attributes() {
@@ -486,9 +481,8 @@ paddle.Metadata = class {
             let items = JSON.parse(data);
             if (items) {
                 for (const item of items) {
-                    if (item.name && item.schema) {
-                        this._map[item.name] = item.schema;
-                    }
+                    item.schema.name = item.name;
+                    this._map[item.name] = item.schema;
                 }
             }
         }

+ 2 - 38
src/pytorch.js

@@ -6,7 +6,6 @@
 var pytorch = pytorch || {};
 var base = base || require('./base');
 var long = long || { Long: require('long') };
-var marked = marked || require('marked');
 
 pytorch.ModelFactory = class {
 
@@ -542,43 +541,8 @@ pytorch.Node = class {
         return index === -1 ? this._type : this._type.substring(0, index);
     }
 
-    get category() {
-        const schema = this._metadata.type(this._type);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        let schema = this._metadata.type(this._type);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this.operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
+    get metadata() {
+        return this._metadata.type(this._type);
     }
 
     get function() {

+ 3 - 45
src/sklearn.js

@@ -5,7 +5,6 @@
 
 var sklearn = sklearn || {};
 var long = long || { Long: require('long') };
-var marked = marked || require('marked');
 
 sklearn.ModelFactory = class {
 
@@ -624,50 +623,8 @@ sklearn.Node = class {
         return this._group ? this._group : null;
     }
 
-    get documentation() {
-        let schema = this._metadata.type(this.operator);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this.operator;
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    if (attribute.description) {
-                        attribute.description = marked(attribute.description);
-                    }
-                }
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            if (schema.references) {
-                for (const reference of schema.references) {
-                    if (reference) {
-                        reference.description = marked(reference.description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
-    }
-
-    get category() {
-        const schema = this._metadata.type(this.operator);
-        return (schema && schema.category) ? schema.category : '';
+    get metadata() {
+        return this._metadata.type(this.operator);
     }
 
     get inputs() {
@@ -994,6 +951,7 @@ sklearn.Metadata = class {
             if (items) {
                 for (const item of items) {
                     if (item.name && item.schema) {
+                        item.schema.name = item.name;
                         this._map[item.name] = item.schema;
                     }
                 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 21 - 861
src/tf-metadata.json


+ 3 - 74
src/tf.js

@@ -7,7 +7,6 @@ var tf = tf || {};
 var long = long || { Long: require('long') };
 var protobuf = protobuf || require('protobufjs');
 var prototxt = prototxt || require('protobufjs/ext/prototxt');
-var marked = marked || require('marked');
 
 tf.ModelFactory = class {
 
@@ -890,79 +889,8 @@ tf.Node = class {
         return null;
     }
 
-    get documentation() {
-        let schema = this._graph.metadata.type(this.operator);
-        if (schema) {
-            schema = JSON.parse(JSON.stringify(schema));
-            schema.name = this.operator;
-            if (schema.summary) {
-                schema.summary = marked(schema.summary);
-            }
-            if (schema.description) {
-                schema.description = marked(schema.description);
-            }
-            if (schema.inputs) {
-                for (const input of schema.inputs) {
-                    if (input.type) {
-                        input.type = tf.Tensor.formatDataType(input.type);
-                    }
-                    else if (input.typeAttr) {
-                        input.type = input.typeAttr;
-                    }
-                    else if (input.typeListAttr) {
-                        input.type = input.typeListAttr;
-                    }
-                    if (input.description) {
-                        input.description = marked(input.description);
-                    }
-                }
-            }
-            if (schema.outputs) {
-                for (const output of schema.outputs) {
-                    if (output.type) {
-                        output.type = tf.Tensor.formatDataType(output.type);
-                    }
-                    else if (output.typeAttr) {
-                        output.type = output.typeAttr;
-                    }
-                    else if (output.typeListAttr) {
-                        output.type = output.typeListAttr;
-                    }
-                    if (output.description) {
-                        output.description = marked(output.description);
-                    }
-                }
-            }
-            if (schema.attributes) {
-                for (const attribute of schema.attributes) {
-                    let description = attribute.description;
-                    if (attribute.allowedValues) {
-                        let allowedValues = tf.GraphMetadata._formatAttributeValue(attribute.allowedValues);
-                        allowedValues = Array.isArray(allowedValues) ? allowedValues : [ allowedValues ];
-                        allowedValues = allowedValues.map((item) => '`' + item + '`').join(', ');
-                        allowedValues = 'Must be one of the following: ' + allowedValues + '.';
-                        description = description ? (allowedValues + ' ' + description) : allowedValues;
-                    }
-                    if (attribute.defaultValue) {
-                        let defaultValue = tf.GraphMetadata._formatAttributeValue(attribute.defaultValue);
-                        defaultValue = Array.isArray(defaultValue) ? defaultValue : [ defaultValue ];
-                        defaultValue = defaultValue.map((item) => '`' + item + '`').join(', ');
-                        defaultValue = 'Defaults to ' + defaultValue + '.';
-                        description = description ? (defaultValue + ' ' + description) : defaultValue;
-                    }
-                    if (description) {
-                        attribute.description = marked(description);
-                    }
-                }
-            }
-            return schema;
-        }
-        return '';
-    }
-
-    get category() {
-        const schema = this._graph.metadata.type(this.operator);
-        return (schema && schema.category) ? schema.category : '';
+    get metadata() {
+        return this._graph.metadata.type(this.operator);
     }
 
     get inputs() {
@@ -1726,6 +1654,7 @@ tf.Metadata = class {
                 if (items) {
                     for (const item of items) {
                         if (item.name && item.schema) {
+                            item.schema.name = item.name;
                             this._map[item.name] = item.schema;
                         }
                     }

+ 7 - 13
src/tflite.js

@@ -293,22 +293,17 @@ tflite.Node = class {
         return null;
     }
 
-    get documentation() {
-        return '';
+    get metadata() {
+        if (this._operator.custom) {
+            return { name: this.operator, category: 'custom' };
+        }
+        return this._metadata.type(this.operator);
     }
 
     get group() {
         return null;
     }
 
-    get category() {
-        if (this._operator.custom) {
-            return 'custom';
-        }
-        const schema = this._metadata.type(this.operator);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
     get inputs() {
         return this._inputs;
     }
@@ -697,9 +692,8 @@ tflite.Metadata = class {
             const items = JSON.parse(data);
             if (items) {
                 for (const item of items) {
-                    if (item.name && item.schema) {
-                        this._map[item.name] = item.schema;
-                    }
+                    item.schema.name = item.name;
+                    this._map[item.name] = item.schema;
                 }
             }
         }

+ 4 - 10
src/torch.js

@@ -405,13 +405,8 @@ torch.Node = class {
         return this._group;
     }
 
-    get category() {
-        const schema = this._metadata.type(this._type);
-        return (schema && schema.category) ? schema.category : '';
-    }
-
-    get documentation() {
-        return '';
+    get metadata() {
+        return this._metadata.type(this._type);
     }
 
     get attributes() {
@@ -640,9 +635,8 @@ torch.Metadata = class {
             let items = JSON.parse(data);
             if (items) {
                 for (const item of items) {
-                    if (item.name && item.schema) {
-                        this._map[item.name] = item.schema;
-                    }
+                    item.schema.name = item.name;
+                    this._map[item.name] = item.schema;
                 }
             }
         }

+ 1 - 1
src/view-sidebar.css

@@ -54,7 +54,7 @@
 .sidebar-view-documentation dl dt { font-size: 13px; font-weight: bold; padding: 0; margin-top: 16px; margin-left: 0px; }
 .sidebar-view-documentation dd { padding: 0 16px; margin-left: 0; margin-bottom: 16px; }
 .sidebar-view-documentation ul { margin-top: 6px; margin-bottom: 6px; padding-left: 20px; }
-
+.sidebar-view-documentation blockquote { margin-left: 15px; margin-right: 15px; }
 
 @media (prefers-color-scheme: dark) {
     .sidebar html { color: #dfdfdf; }

+ 51 - 8
src/view-sidebar.js

@@ -4,6 +4,7 @@
 var sidebar = sidebar || {};
 var long = long || { Long: require('long') };
 var Handlebars = Handlebars || require('handlebars');
+var marked = marked || require('marked');
 
 sidebar.Sidebar = class {
 
@@ -141,7 +142,7 @@ sidebar.NodeSidebar = class {
 
         if (node.operator) {
             let showDocumentation = null;
-            if (node.documentation) {
+            if (node.metadata) {
                 showDocumentation = {};
                 showDocumentation.text = '?';
                 showDocumentation.callback = () => {
@@ -871,7 +872,7 @@ sidebar.ModelSidebar = class {
     }
 };
 
-sidebar.OperatorDocumentationSidebar = class {
+sidebar.DocumentationSidebar = class {
 
     constructor(documentation) {
         this._documentation = documentation;
@@ -880,6 +881,7 @@ sidebar.OperatorDocumentationSidebar = class {
     render() {
         if (!this._elements) {
             this._elements = [];
+            const documentation = sidebar.DocumentationSidebar.formatDocumentation(this._documentation);
             let template = `
 <div id='documentation' class='sidebar-view-documentation'>
 
@@ -957,11 +959,10 @@ In domain <tt>{{{domain}}}</tt> since version <tt>{{{since_version}}}</tt> at su
 
 </div>
 `;
-            let generator = Handlebars.compile(template, 'utf-8');
-            let html = generator(this._documentation);
-            let parser = new DOMParser();
-            let document = parser.parseFromString(html, 'text/html');
-            let element = document.firstChild;
+            const generator = Handlebars.compile(template, 'utf-8');
+            const html = generator(documentation);
+            const document = new DOMParser().parseFromString(html, 'text/html');
+            const element = document.body.firstChild;
             element.addEventListener('click', (e) => {
                 if (e.target && e.target.href) {
                     let link = e.target.href;
@@ -989,6 +990,48 @@ In domain <tt>{{{domain}}}</tt> since version <tt>{{{since_version}}}</tt> at su
             }
         }
     }
+
+    static formatDocumentation(data) {
+        if (data) {
+            data = JSON.parse(JSON.stringify(data));
+            if (data.summary) {
+                data.summary = marked(data.summary);
+            }
+            if (data.description) {
+                data.description = marked(data.description);
+            }
+            if (data.attributes) {
+                for (const attribute of data.attributes) {
+                    if (attribute.description) {
+                        attribute.description = marked(attribute.description);
+                    }
+                }
+            }
+            if (data.inputs) {
+                for (const input of data.inputs) {
+                    if (input.description) {
+                        input.description = marked(input.description);
+                    }
+                }
+            }
+            if (data.outputs) {
+                for (const output of data.outputs) {
+                    if (output.description) {
+                        output.description = marked(output.description);
+                    }
+                }
+            }
+            if (data.references) {
+                for (const reference of data.references) {
+                    if (reference) {
+                        reference.description = marked(reference.description);
+                    }
+                }
+            }
+            return data;
+        }
+        return '';
+    }
 };
 
 sidebar.FindSidebar = class {
@@ -1152,6 +1195,6 @@ if (typeof module !== 'undefined' && typeof module.exports === 'object') {
     module.exports.Sidebar = sidebar.Sidebar;
     module.exports.ModelSidebar = sidebar.ModelSidebar;
     module.exports.NodeSidebar = sidebar.NodeSidebar;
-    module.exports.OperatorDocumentationSidebar = sidebar.OperatorDocumentationSidebar;
+    module.exports.DocumentationSidebar = sidebar.DocumentationSidebar;
     module.exports.FindSidebar = sidebar.FindSidebar;
 }

+ 5 - 4
src/view.js

@@ -426,7 +426,8 @@ view.View = class {
 
                         let header =  element.block('header');
                         let styles = [ 'node-item-operator' ];
-                        const category = node.category;
+                        const metadata = node.metadata;
+                        const category = metadata && metadata.category ? metadata.category : '';
                         if (category) {
                             styles.push('node-item-operator-' + category.toLowerCase());
                         }
@@ -936,9 +937,9 @@ view.View = class {
     }
 
     showOperatorDocumentation(node) {
-        let documentation = node.documentation;
-        if (documentation) {
-            const documentationSidebar = new sidebar.OperatorDocumentationSidebar(documentation);
+        let metadata = node.metadata;
+        if (metadata) {
+            const documentationSidebar = new sidebar.DocumentationSidebar(metadata);
             documentationSidebar.on('navigate', (sender, e) => {
                 this._host.openURL(e.link);
             });

+ 5 - 2
test/test.js

@@ -499,8 +499,11 @@ function loadModel(target, item) {
                 node.name.toString();
                 node.name.length;
                 node.description;
-                node.documentation.toString();
-                node.category.toString();
+                const metadata = node.metadata;
+                if (metadata !== null && metadata !== undefined && (typeof metadata !== 'object' || !metadata.name)) {
+                    throw new Error("Invalid documentation object '" + node.operator + "'.");
+                }
+                sidebar.DocumentationSidebar.formatDocumentation(node.metadata);
                 for (const attribute of node.attributes) {
                     attribute.name.toString();
                     attribute.name.length;

+ 24 - 4
tools/onnx-script.py

@@ -6,6 +6,7 @@ import onnx
 import json
 import io
 import os
+import re
 import sys
 
 from onnx import defs
@@ -118,6 +119,21 @@ def generate_json_types(types):
     r = sorted(r)
     return r
 
+def format_range(value):
+    if value == 2147483647:
+        return '&#8734;'
+    return str(value)
+
+def format_description(description):
+    def replace_line(match):
+        link = match.group(1)
+        url = match.group(2)
+        if not url.startswith("http://") and not url.startswith("https://"):
+            url = "https://github.com/onnx/onnx/blob/master/docs/" + url
+        return "[" + link + "](" + url + ")";
+    description = re.sub("\\[(.+)\\]\\(([^ ]+?)( \"(.+)\")?\\)", replace_line, description)
+    return description
+
 def generate_json(schemas, json_file):
     json_root = []
     for schema in schemas:
@@ -129,13 +145,13 @@ def generate_json(schemas, json_file):
         json_schema['since_version'] = schema.since_version
         json_schema['support_level'] = generate_json_support_level_name(schema.support_level)
         if schema.doc:
-            json_schema['description'] = schema.doc.lstrip()
+            json_schema['description'] = format_description(schema.doc.lstrip())
         if schema.inputs:
             json_schema['inputs'] = []
             for input in schema.inputs:
                 json_input = {}
                 json_input['name'] = input.name
-                json_input['description'] = input.description
+                json_input['description'] = format_description(input.description)
                 json_input['type'] = input.typeStr
                 if input.option == OpSchema.FormalParameterOption.Optional:
                     json_input['option'] = 'optional'
@@ -149,7 +165,7 @@ def generate_json(schemas, json_file):
             for output in schema.outputs:
                 json_output = {}
                 json_output['name'] = output.name
-                json_output['description'] = output.description
+                json_output['description'] = format_description(output.description)
                 json_output['type'] = output.typeStr
                 if output.option == OpSchema.FormalParameterOption.Optional:
                     json_output['option'] = 'optional'
@@ -158,12 +174,16 @@ def generate_json(schemas, json_file):
                 json_schema['outputs'].append(json_output)
         json_schema['min_output'] = schema.min_output
         json_schema['max_output'] = schema.max_output
+        if schema.min_input != schema.max_input:
+            json_schema['inputs_range'] = format_range(schema.min_input) + ' - ' + format_range(schema.max_input);
+        if schema.min_output != schema.max_output:
+            json_schema['outputs_range'] = format_range(schema.min_output) + ' - ' + format_range(schema.max_output);
         if schema.attributes:
             json_schema['attributes'] = []
             for _, attribute in sorted(schema.attributes.items()):
                 json_attribute = {}
                 json_attribute['name'] = attribute.name
-                json_attribute['description'] = attribute.description
+                json_attribute['description'] = format_description(attribute.description)
                 attribute_type = generate_json_attr_type(attribute.type)
                 if attribute_type:
                     json_attribute['type'] = attribute_type

+ 72 - 2
tools/tf-script.py

@@ -8,6 +8,7 @@ import os
 
 from tensorflow.core.framework import api_def_pb2
 from tensorflow.core.framework import op_def_pb2
+from tensorflow.core.framework import types_pb2
 from google.protobuf import text_format
 
 def metadata():
@@ -190,6 +191,71 @@ def metadata():
             return convert_shape(attr_value.shape)
         raise Exception()
 
+    _TYPE_TO_STRING = {
+        types_pb2.DataType.DT_HALF: "float16",
+        types_pb2.DataType.DT_FLOAT: "float32",
+        types_pb2.DataType.DT_DOUBLE: "float64",
+        types_pb2.DataType.DT_INT32: "int32",
+        types_pb2.DataType.DT_UINT8: "uint8",
+        types_pb2.DataType.DT_UINT16: "uint16",
+        types_pb2.DataType.DT_UINT32: "uint32",
+        types_pb2.DataType.DT_UINT64: "uint64",
+        types_pb2.DataType.DT_INT16: "int16",
+        types_pb2.DataType.DT_INT8: "int8",
+        types_pb2.DataType.DT_STRING: "string",
+        types_pb2.DataType.DT_COMPLEX64: "complex64",
+        types_pb2.DataType.DT_COMPLEX128: "complex128",
+        types_pb2.DataType.DT_INT64: "int64",
+        types_pb2.DataType.DT_BOOL: "bool",
+        types_pb2.DataType.DT_QINT8: "qint8",
+        types_pb2.DataType.DT_QUINT8: "quint8",
+        types_pb2.DataType.DT_QINT16: "qint16",
+        types_pb2.DataType.DT_QUINT16: "quint16",
+        types_pb2.DataType.DT_QINT32: "qint32",
+        types_pb2.DataType.DT_BFLOAT16: "bfloat16",
+        types_pb2.DataType.DT_RESOURCE: "resource",
+        types_pb2.DataType.DT_VARIANT: "variant",
+        types_pb2.DataType.DT_HALF_REF: "float16_ref",
+        types_pb2.DataType.DT_FLOAT_REF: "float32_ref",
+        types_pb2.DataType.DT_DOUBLE_REF: "float64_ref",
+        types_pb2.DataType.DT_INT32_REF: "int32_ref",
+        types_pb2.DataType.DT_UINT32_REF: "uint32_ref",
+        types_pb2.DataType.DT_UINT8_REF: "uint8_ref",
+        types_pb2.DataType.DT_UINT16_REF: "uint16_ref",
+        types_pb2.DataType.DT_INT16_REF: "int16_ref",
+        types_pb2.DataType.DT_INT8_REF: "int8_ref",
+        types_pb2.DataType.DT_STRING_REF: "string_ref",
+        types_pb2.DataType.DT_COMPLEX64_REF: "complex64_ref",
+        types_pb2.DataType.DT_COMPLEX128_REF: "complex128_ref",
+        types_pb2.DataType.DT_INT64_REF: "int64_ref",
+        types_pb2.DataType.DT_UINT64_REF: "uint64_ref",
+        types_pb2.DataType.DT_BOOL_REF: "bool_ref",
+        types_pb2.DataType.DT_QINT8_REF: "qint8_ref",
+        types_pb2.DataType.DT_QUINT8_REF: "quint8_ref",
+        types_pb2.DataType.DT_QINT16_REF: "qint16_ref",
+        types_pb2.DataType.DT_QUINT16_REF: "quint16_ref",
+        types_pb2.DataType.DT_QINT32_REF: "qint32_ref",
+        types_pb2.DataType.DT_BFLOAT16_REF: "bfloat16_ref",
+        types_pb2.DataType.DT_RESOURCE_REF: "resource_ref",
+        types_pb2.DataType.DT_VARIANT_REF: "variant_ref",
+    }
+
+    def format_data_type(data_type):
+        if data_type in _TYPE_TO_STRING:
+            return _TYPE_TO_STRING[data_type]
+        raise Exception()
+
+    def format_attribute_value(value):
+        if type(value) is dict and 'type' in value and 'value' in value and value['type'] == 'type':
+            return format_data_type(value['value'])
+        if type(value) is str:
+            return value
+        if value == True:
+            return 'true'
+        if value == False:
+            return 'false'
+        raise Exception()
+
     tensorflow_repo_dir = os.path.join(os.path.dirname(__file__), '../third_party/src/tensorflow')
     api_def_map = read_api_def_map(os.path.join(tensorflow_repo_dir, 'tensorflow/core/api_def/base_api'))
     input_file = os.path.join(tensorflow_repo_dir, 'tensorflow/core/ops/ops.pbtxt')
@@ -241,9 +307,13 @@ def metadata():
             if attr.has_minimum:
                 json_attribute['minimum'] = attr.minimum
             if attr.HasField('allowed_values'):
-                json_attribute['allowedValues'] = convert_attr_value(attr.allowed_values)
+                allowed_values = convert_attr_value(attr.allowed_values)
+                description = json_attribute['description'] + ' ' if 'description' in json_attribute else ''
+                description = description + 'Must be one of the following: ' + ', '.join(list(map(lambda x: "`" + format_attribute_value(x) + "`", allowed_values))) + '.'
+                json_attribute['description'] = description
             if attr.HasField('default_value'):
-                json_attribute['default'] = convert_attr_value(attr.default_value)
+                default_value = convert_attr_value(attr.default_value)
+                json_attribute['default'] = default_value
             json_schema['attributes'].append(json_attribute)
         for input_arg in op.input_arg:
             if not 'inputs' in json_schema:

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor