Not Found: FeedInputs: Cannot Find TensorFlow Feed Out

I tried to use this example of using the Tensorflow-preserving model in C ++ on this website: https://medium.com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f# .ji310n4zo

It works well. But it does not save the values โ€‹โ€‹of the variables a and b , since it saves the graph not variables. I tried replacing the following line:

tf.train.write_graph(sess.graph_def, 'models/', 'graph.pb', as_text=False)

from

saver.save(sess, 'models/graph', global_step=0)

of course, after creating the guardian object. It does not work and outputs:

Not Found: FeedInputs: Cannot Find Feed Out

I checked the Nodes for Downloadable Nodes, and they only:

_SOURCE

_SINK

and in the write_graph function, and then load the model in C ++, I loaded the following nodes:

_SOURCE

_SINK

save / restore_slice_1 / shape_and_slice

/restore_slice_1/tensor_name

/restore_slice/shape_and_slice

/restore_slice/tensor_name

//shapes_and_slices

//tensor_names

/Const

/restore_slice_1

/restore_slice

/Assign_1

/

/initial_value

/

/

/restore_all

/

/control_dependency

/

/initial_value

/

INIT

, saver.save(), , 165B, , write_graph, 1.9KB.

+4
2

, , , , .

write_graph , python write_graph:

for v in tf.trainable_variables():
    vc = tf.constant(v.eval())
    tf.assign(v, vc, name="assign_variables")

, , " assign_variables", . , write_graph, .

" assign_variables" c, , , . :

      Status status = NewSession(SessionOptions(), &session);
      std::vector<tensorflow::Tensor> outputs;
      for(int i = 0;status.ok(); i++) {
        char name[100];
        if (i==0)
            sprintf(name, "assign_variables");
        else
            sprintf(name, "assign_variables_%d", i);

        status = session->Run({}, {name}, {}, &outputs);
      }
+2

, save/restore_all, :

std::vector<tensorflow::Tensor> outputs;
Tensor checkpoint_filepath(DT_STRING, TensorShape());
checkpoint_filepath.scalar<std::string>()() = "path to the checkpoint file";
status = session->Run( {{ "save/Const", checkpoint_filepath },}, 
                       {}, {"save/restore_all"}, &outputs);
+1

Source: https://habr.com/ru/post/1624316/


All Articles