Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / mo / front / caffe / loader.py
index 69f63f2..40dd09c 100644 (file)
@@ -1,5 +1,5 @@
 """
- Copyright (c) 2018 Intel Corporation
+ Copyright (c) 2018-2019 Intel Corporation
 
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
@@ -18,14 +18,12 @@ import logging as log
 import mmap
 import os
 
-
-import networkx as nx
 import numpy as np
 from google.protobuf import text_format
 from google.protobuf.internal import api_implementation
 
 from mo.front.caffe.proto import caffe_pb2
-from mo.graph.graph import Node, unique_id
+from mo.graph.graph import Node, Graph
 from mo.utils.error import Error, FrameworkError
 from mo.utils.utils import refer_to_faq_msg
 
@@ -165,10 +163,10 @@ def caffe_pb_to_nx(proto, model):
 
     Returns
     ----------
-    nx.MultiDiGraph
+        Graph
         built NX Directed graph.
     """
-    graph = nx.MultiDiGraph()
+    graph = Graph()
     # Blobs in prototxt model can be reused by inplace layer.
     # This requires loading of pb layers in order and tracking the latest
     # layer that writes a particular blob.
@@ -282,7 +280,7 @@ def caffe_pb_to_nx(proto, model):
                 input_dims.append(np.array(list(dims), dtype=np.int64))
                 input_names.append(layer.name)
 
-        layer.name = unique_id(graph, layer.name)        
+        layer.name = graph.unique_id(layer.name)
         graph.add_node(layer.name, pb=layer, model_pb=model_layer, kind='op')
 
         # connect inputs based on blob_producers dictionary
@@ -307,27 +305,6 @@ def caffe_pb_to_nx(proto, model):
                 log.debug("Detected reuse of blob {} by layer {}".format(top, layer.name))
             blob_producers[top] = (layer.name, src_port)
 
-    # Find all nodes that do not have consumers.
-    # Add identity ops as a consumers for each output port for such nodes.
-    for node in list(graph.nodes()):
-        node = Node(graph, node)
-        if len(node.out_nodes()) == 0:
-            if not node.has_valid('pb') or not hasattr(node.pb, 'top'):
-                continue
-            for port, top in enumerate(node.pb.top):
-                new_id = unique_id(graph, 'TerminalIdentity_')
-                graph.add_node(new_id, op='Identity', type='Identity', kind='op')
-                edge_attrs = {
-                    'out': port,
-                    'in': 0,
-                    'name': top,
-                    'fw_tensor_debug_info': [(node.id, top)], # debug anchor for a framework tensor name and port
-                    'in_attrs': ['in', 'name'],
-                    'out_attrs': ['out', 'name'],
-                    'data_attrs': ['fw_tensor_debug_info']
-                }
-                graph.add_edge(node.id, new_id, **edge_attrs)
-
     if len(input_names) <= 0:
         raise Error('The topology contains no "input" layers. ' +
                     refer_to_faq_msg(79))