in source/neuropod/backends/tensorflow/tf_backend.cc [173:212]
void TensorflowNeuropodBackend::load_frozen_graph(std::istream &graph_stream)
{
// Create a buffer of the right size
graph_stream.seekg(0, graph_stream.end);
auto graph_length = static_cast<size_t>(graph_stream.tellg());
std::vector<char> buffer(graph_length);
// Read into the buffer
graph_stream.seekg(0, graph_stream.beg);
graph_stream.read(buffer.data(), static_cast<std::streamsize>(graph_length));
if (graph_stream.fail())
{
NEUROPOD_ERROR("Error reading TensorFlow GraphDef for neuropod {}", neuropod_path_);
}
// Read the GraphDef
tensorflow::GraphDef graph;
tensorflow::ParseProtoUnlimited(&graph, buffer.data(), buffer.size());
// Move the graph to the target device
move_graph_to_device(graph, *session_, options_.visible_device);
// Create a session
auto status = session_->Create(graph);
if (!status.ok())
{
NEUROPOD_ERROR("Error loading TensorFlow graph: {}", status.error_message());
}
// Setup the nodename mapping and get the init ops (if any)
std::vector<std::string> init_ops;
auto config_stream = loader_->get_istream_for_file("0/config.json");
setup_node_mapping_and_init_ops(*config_stream, node_name_mapping_, init_ops);
// Run init ops if any
for (const auto &op_name : init_ops)
{
check_tf_status(session_->Run({}, {}, {op_name}, nullptr));
}
}