connect input and output tensors of two different graphs tensorflow

后端 未结 2 794
暖寄归人
暖寄归人 2020-12-05 12:26

I have 2 ProtoBuf Files, I currently load and forward pass each of them separately, by calling-

out1=session.run(graph1out, feed_di         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 12:54

    Assuming that your Protobuf files contain serialized tf.GraphDef protos, you can use the input_map argument of tf.import_graph_def() to connect the two graphs:

    # Import graph1.
    graph1_def = ...  # tf.GraphDef object
    out1_name = "..."  # name of the graph1out tensor in graph1_def.
    graph1out, = tf.import_graph_def(graph1_def, return_elements=[out_name])
    
    # Import graph2 and connect it to graph1.
    graph2_def = ...  # tf.GraphDef object
    inp2_name = "..."  # name of the graph2inp tensor in graph2_def.
    out2_name = "..."  # name of the graph2out tensor in graph2_def.
    graph2out, = tf.import_graph_def(graph2_def, input_map={inp2_name: graph1out},
                                     return_elements=[out2_name])
    

提交回复
热议问题