MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / main

Function main

tensorflow/examples/label_image/main.cc:277–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277int main(int argc, char* argv[]) {
278 // These are the command-line flags the program can understand.
279 // They define where the graph and input data is located, and what kind of
280 // input the model expects. If you train your own model, or use something
281 // other than inception_v3, then you'll need to update these.
282 string image = "tensorflow/examples/label_image/data/grace_hopper.jpg";
283 string graph =
284 "tensorflow/examples/label_image/data/inception_v3_2016_08_28_frozen.pb";
285 string labels =
286 "tensorflow/examples/label_image/data/imagenet_slim_labels.txt";
287 int32 input_width = 299;
288 int32 input_height = 299;
289 float input_mean = 0;
290 float input_std = 255;
291 string input_layer = "input";
292 string output_layer = "InceptionV3/Predictions/Reshape_1";
293 bool self_test = false;
294 string root_dir = "";
295 std::vector<Flag> flag_list = {
296 Flag("image", &image, "image to be processed"),
297 Flag("graph", &graph, "graph to be executed"),
298 Flag("labels", &labels, "name of file containing labels"),
299 Flag("input_width", &input_width, "resize image to this width in pixels"),
300 Flag("input_height", &input_height,
301 "resize image to this height in pixels"),
302 Flag("input_mean", &input_mean, "scale pixel values to this mean"),
303 Flag("input_std", &input_std, "scale pixel values to this std deviation"),
304 Flag("input_layer", &input_layer, "name of input layer"),
305 Flag("output_layer", &output_layer, "name of output layer"),
306 Flag("self_test", &self_test, "run a self test"),
307 Flag("root_dir", &root_dir,
308 "interpret image and graph file names relative to this directory"),
309 };
310 string usage = tensorflow::Flags::Usage(argv[0], flag_list);
311 const bool parse_result = tensorflow::Flags::Parse(&argc, argv, flag_list);
312 if (!parse_result) {
313 LOG(ERROR) << usage;
314 return -1;
315 }
316
317 // We need to call this to set up global state for TensorFlow.
318 tensorflow::port::InitMain(argv[0], &argc, &argv);
319 if (argc > 1) {
320 LOG(ERROR) << "Unknown argument " << argv[1] << "\n" << usage;
321 return -1;
322 }
323
324 // First we load and initialize the model.
325 std::unique_ptr<tensorflow::Session> session;
326 string graph_path = tensorflow::io::JoinPath(root_dir, graph);
327 Status load_graph_status = LoadGraph(graph_path, &session);
328 if (!load_graph_status.ok()) {
329 LOG(ERROR) << load_graph_status;
330 return -1;
331 }
332
333 // Get the image from disk as a float array of numbers, resized and normalized
334 // to the specifications the main graph expects.

Callers

nothing calls this directly

Calls 11

UsageFunction · 0.85
ParseFunction · 0.85
LoadGraphFunction · 0.70
ReadTensorFromImageFileFunction · 0.70
CheckTopLabelFunction · 0.70
PrintTopLabelsFunction · 0.70
FlagClass · 0.50
InitMainFunction · 0.50
JoinPathFunction · 0.50
okMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected