cjweeks / tensorflow-cmake

Integrate TensorFlow with CMake projects effortlessly
MIT License
331 stars 83 forks source link

graph.pb syntax error #5

Closed ahx-code closed 7 years ago

ahx-code commented 7 years ago

Hi

When I build the first example; I have the following error:

/usr/bin/ld:/home/ahmet/tensorflow-cmake/examples/TensorFlowTest/graph.pb: file format not recognized; treating as linker script

Also When I compiled graph.pb with PureBasic, gave me an syntax error.

Is it possible graph.pb damaged? Am I missing a point?

include "tensorflow/core/public/session.h"

include "tensorflow/core/platform/env.h"

include "tensorflow/core/framework/graph.pb.h"

Here is the code of example ( Currently I am compiling with Qt 5.7.0 w/ gcc-5 (5.4.1) )

/**

int main(int argc, char\ argv) { namespace tf = tensorflow;

tf::Session* session;
tf::Status status = tf::NewSession(tf::SessionOptions(), &session);
checkStatus(status);

tf::GraphDef graph_def;
status = ReadBinaryProto(tf::Env::Default(), "graph.pb", &graph_def);
checkStatus(status);

status = session->Create(graph_def);
checkStatus(status);

tf::Tensor x(tf::DT_FLOAT, tf::TensorShape()), y(tf::DT_FLOAT, tf::TensorShape());
x.scalar<float>()() = 23.0;
y.scalar<float>()() = 19.0;

std::vector<std::pair<tf::string, tf::Tensor>> input_tensors = {{"x", x}, {"y", y}};
std::vector<tf::Tensor> output_tensors;

status = session->Run(input_tensors, {"z"}, {}, &output_tensors);
checkStatus(status);

tf::Tensor output = output_tensors[0];
std::cout << "Success: " << output.scalar<float>() << "!" << std::endl;
session->Close();
return 0;

}

cjweeks commented 7 years ago

The graph.pb file is a protobuf file specifying a simple computational graph, which returns the addition of two scalars. This file does not need to be compiled, as its contents are read from the sample C++ programs at runtime. Therefore, avoid including this file in any list of source files CMake (or QMake) requires. It is important to note that the included header, tensorflow/core/framework/graph.pb.h, is completely different from the local graph.pb; the former is a header file in the TensorFlow library.