@@ -68,10 +68,7 @@ int main(int argc, char* argv[]) {
68
68
std::cout << " Session created successfully" << std::endl;
69
69
}
70
70
71
- // Read in the protobuf graph we exported
72
- // (The path seems to be relative to the cwd. Keep this in mind
73
- // when using `bazel run` since the cwd isn't where you call
74
- // `bazel run` but from inside a temp folder.)
71
+ // Load graph protobuf
75
72
GraphDef graph_def;
76
73
std::string graph_path = argv[3 ];
77
74
status = ReadBinaryProto (Env::Default (), graph_path, &graph_def);
@@ -91,7 +88,7 @@ int main(int argc, char* argv[]) {
91
88
}
92
89
93
90
// Setup inputs and outputs
94
- // input 9:283:1 6:384:1 152:384:1
91
+ // demo instance: " 9:283:1 6:384:1 152:384:1"
95
92
std::string libfm_data = " 9:283:1 6:384:1 152:384:1" ;
96
93
std::unordered_map<int64, std::unordered_map<int64, float > > instance;
97
94
std::vector<std::string> features;
@@ -160,7 +157,7 @@ int main(int argc, char* argv[]) {
160
157
// The session will initialize the outputs
161
158
std::vector<tensorflow::Tensor> outputs;
162
159
163
- // Run the session, evaluating our "logit " operation from the graph
160
+ // Run the session, evaluating our "predict/add " operation from the graph
164
161
status = session->Run (inputs, {" predict/add" }, {}, &outputs);
165
162
if (!status.ok ()) {
166
163
std::cerr << status.ToString () << std::endl;
@@ -169,18 +166,16 @@ int main(int argc, char* argv[]) {
169
166
std::cout << " Run session successfully" << std::endl;
170
167
}
171
168
172
- // Grab the first output (we only evaluated one graph node: "logit ")
169
+ // Grab the first output (we only evaluated one graph node: "predict/add ")
173
170
// and convert the node to a scalar representation.
174
171
auto output_softmax = outputs[0 ].scalar <float >();
175
172
176
- // (There are similar methods for vectors and matrices here:
177
- // https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/public/tensor.h)
178
-
179
173
// Print the results
180
174
std::cout << outputs[0 ].DebugString () << std::endl;
181
175
std::cout << " output value: " << output_softmax () << std::endl;
182
176
183
177
// Free any resources used by the session
184
178
session->Close ();
179
+
185
180
return 0 ;
186
181
}
0 commit comments