Переглянути джерело

Update caffe2-metadata.json

Lutz Roeder 5 роки тому
батько
коміт
f1c1354f86
4 змінених файлів з 22 додано та 48 видалено
  1. 0 18
      source/caffe2-metadata.json
  2. 4 11
      source/caffe2.js
  3. 14 13
      tools/caffe2-script.py
  4. 4 6
      tools/pytorch-script.py

Різницю між файлами не показано, бо вона завелика
+ 0 - 18
source/caffe2-metadata.json


+ 4 - 11
source/caffe2.js

@@ -791,23 +791,16 @@ caffe2.Metadata = class {
     }
 
     constructor(data) {
-        this._map = {};
+        this._map = new Map();
         this._attributeCache = {};
         if (data) {
-            const items = JSON.parse(data);
-            if (items) {
-                for (const item of items) {
-                    if (item.name && item.schema) {
-                        item.schema.name = item.name;
-                        this._map[item.name] = item.schema;
-                    }
-                }
-            }
+            const metadata = JSON.parse(data);
+            this._map = new Map(metadata.map((item) => [ item.name, item ]));
         }
     }
 
     type(name) {
-        return this._map[name] || null;
+        return this._map.get(name);
     }
 
     attribute(type, name) {

+ 14 - 13
tools/caffe2-script.py

@@ -122,7 +122,8 @@ def update_input(schema, input_desc):
         input_arg = {}
         input_arg['name'] = input_name
         schema['inputs'].append(input_arg)
-    input_arg['description'] = description
+    if description:
+        input_arg['description'] = description
     if len(input_desc) > 2:
         return
 
@@ -140,7 +141,8 @@ def update_output(operator_name, schema, output_desc):
         output_arg = {}
         output_arg['name'] = output_name
         schema['outputs'].append(output_arg)
-    output_arg['description'] = description
+    if description:
+        output_arg['description'] = description
     if len(output_desc) > 2:
         return
 
@@ -160,10 +162,9 @@ def metadata():
 
     schema_map = {}
 
-    for entry in json_root:
-        operator_name = entry['name']
-        schema = entry['schema']
-        schema_map[operator_name] = schema
+    for schema in json_root:
+        name = schema['name']
+        schema_map[name] = schema
 
     for operator_name in caffe2.python.core._GetRegisteredOperators():
         op_schema = caffe2.python.workspace.C.OpSchema.get(operator_name)
@@ -173,11 +174,11 @@ def metadata():
             if operator_name in schema_map:
                 schema = schema_map[operator_name]
             else:
-                schema = {}
-                entry = { 'name': operator_name, 'schema': schema }
-                schema_map[operator_name] = entry
-                json_root.append(entry)
-            schema['description'] = op_schema.doc
+                schema = { 'name': operator_name }
+                schema_map[operator_name] = schema
+                json_root.append(schema)
+            if op_schema.doc:
+                schema['description'] = op_schema.doc
             for arg in op_schema.args:
                 update_argument(schema, arg)
             for input_desc in op_schema.input_desc:
@@ -187,7 +188,7 @@ def metadata():
             schema['support_level'] = get_support_level(os.path.dirname(op_schema.file))
 
     with io.open(json_file, 'w', newline='') as fout:
-        json_data = json.dumps(json_root, sort_keys=True, indent=2)
+        json_data = json.dumps(json_root, sort_keys=False, indent=2)
         for line in json_data.splitlines():
             line = line.rstrip()
             if sys.version_info[0] < 3:
@@ -197,5 +198,5 @@ def metadata():
 
 if __name__ == '__main__':
     command_table = { 'metadata': metadata }
-    command = sys.argv[1];
+    command = sys.argv[1]
     command_table[command]()

+ 4 - 6
tools/pytorch-script.py

@@ -19,14 +19,12 @@ def metadata():
 
     schema_map = {}
 
-    for entry in json_root:
-        name = entry['name']
-        schema = entry['schema']
+    for schema in json_root:
+        name = schema['name']
         schema_map[name] = schema
 
-    for entry in json_root:
-        name = entry['name']
-        schema = entry['schema']
+    for schema in json_root:
+        name = schema['name']
         if 'package' in schema:
             class_name = schema['package'] + '.' + name
             # print(class_name)

Деякі файли не було показано, через те що забагато файлів було змінено