0

From Python, I have a frozen graph.pb that I'm currently using in a C++ environment. Now the data for the input tensor are currently preprocessed on the CPU, but I would like to do this step in another GraphDef to run it on the GPU, but I can't seem to find a way to connect nodes between two GraphDef's.

Lets assume my frozen graph have an input/placeholder named mid that I'd like to connect with the preprocessing steps below

tf::GraphDef create_graph_extension() {
    tf::Scope root = tf::Scope::NewRootScope();

    auto a = tf::ops::Const(root.WithOpName("in"), {(float) 23.0, (float) 31.0});
    auto b = tf::ops::Identity(root.WithOpName("mid"), a);

    tf::GraphDef graph;
    TF_CHECK_OK(root.ToGraphDef(&graph));
    return graph;
}

I usually use session->Extend() to run multiple graphs in the same session, but always making sure their node names are unique. With non-unique node names, that I hoped to connect, I get an error

Failed to install graph:
Invalid argument: GraphDef argument to Extend includes node 'mid', which 
was created by a previous call to Create or Extend in this session.

P.s. It seems like it is possible in python at least (link)

Allan Nørgaard
  • 284
  • 2
  • 11

1 Answers1

0

You can achieve what you're looking for using the same idea that was suggested for Python - import one GraphDef into another and remap inputs.

In case you do use the C API (which has stability guarantees), you'd want to look at:

These are implemented on top of the C++ ImportGraphDef function, which you might be able to use directly instead (though that doesn't seem to yet be part of the exported C++ API)

Hope that helps.

ash
  • 6,681
  • 3
  • 18
  • 30