[ MO ] Memory usage (#657)
authorEvgenya Stepyreva <evgenya.stepyreva@intel.com>
Thu, 28 May 2020 11:00:42 +0000 (14:00 +0300)
committerGitHub <noreply@github.com>
Thu, 28 May 2020 11:00:42 +0000 (14:00 +0300)
model-optimizer/mo/back/ie_ir_ver_2/emitter.py
model-optimizer/mo/front/common/partial_infer/concat.py

index 46390b4..4e1c51d 100644 (file)
@@ -61,8 +61,9 @@ def serialize_constants_recursively(graph: Graph, bin_file, data_type, bin_hashe
         node = Node(graph, node)
 
         if node.kind == 'data' and node.value is not None and any('bin' in d for u, v, d in graph.out_edges(node.node, data=True)):
-            blob = node.value
-            blob_hash = hashlib.sha512(blob.tobytes()).hexdigest()
+            # avoid array copying while taking hash
+            blob = node.value if node.value.ndim > 0 else node.value.reshape((1))
+            blob_hash = hashlib.sha512(np.ascontiguousarray(blob).view(np.uint8)).hexdigest()
 
             if blob_hash in bin_hashes and np.array_equal(blob, bin_hashes[blob_hash]['blob']):
                 graph.node[node.node]['offset'] = bin_hashes[blob_hash]['offset']
index 7e0f2dc..6addde9 100644 (file)
@@ -69,7 +69,7 @@ def concat_infer(node):
     if any(v is None for v in values):
         return
 
-    node.out_node(0).value = np.array(np.concatenate(values, axis=node.axis), dtype=values[0].dtype)
+    node.out_node(0).value = np.concatenate(values, axis=node.axis).astype(values[0].dtype, copy=False)
     node.out_node(0).shape = np.array(node.out_node(0).value.shape, dtype=np.int64)