Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Error while predicting image using .pb file in Tensorflow cpp

Please refer the below program:

tensorflow::GraphDef graphDef;
        tensorflow::ReadBinaryProto(tensorflow::Env::Default(), "test10.pb", &graphDef);

        tensorflow::SessionOptions options;
        std::unique_ptr<tensorflow::Session> session(tensorflow::NewSession(options));

        tensorflow::Status sessionCreateStatus = session->Create(graphDef);
        vector<Mat> input_Images;
        Mat input_image = imread (argv[1]);
        input_Images.push_back (input_image);
        int height = 256;
        int width = 256;
        int depth = 3;
        cout << "Input Rows:" << input_image.rows << " Cols:" << input_image.cols << endl;
        tensorflow::Tensor input_tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, input_image.rows, input_image.cols, 3}));
        auto input_tensor_mapped = input_tensor.tensor<float, 4>();
        cout << "Num Images: " << input_Images.size() << endl;

        for (int i = 0; i < input_Images.size(); i++) {
              Mat image = input_Images[i];
              cout << "Image: " << image.cols << "x" << image.rows << " " << image.channels() << endl;
              const float * source_data = (float*) image.data;
              for (int h = 0; h < image.rows; ++h) {
                  const float* source_row = source_data + (h * image.cols * image.channels());
                  for (int w = 0; w < image.cols; ++w) {
                      const float* source_pixel = source_row + (w * image.channels());
                      for (int c = 0; c < image.channels(); ++c) {
                          const float* source_value = source_pixel + c;
                          //cout << i << " " << h << " "<< w << " " << c << endl;
                          //std::cout << *source_value << std::endl;
                          input_tensor_mapped(i, h, w, c) = *source_value;
                      }
                  }
              }
        }
        cout<<"Outside the for loop";
        tensorflow::Tensor phase_tensor(tensorflow::DT_BOOL, tensorflow::TensorShape());
        phase_tensor.scalar<bool>()() = true;

      cout << phase_tensor.DebugString() << endl;
      cout << input_tensor.DebugString() << endl;
        std::vector<tensorflow::Tensor> outputs;

        std::vector<std::pair<string, tensorflow::Tensor>> feed_dict = {
              {input_layer, input_tensor},
              {phase_train_layer, phase_tensor},
        };

        Status run_status = session->Run(feed_dict,
                                      {output_layer}, {} , &outputs);
        if (!run_status.ok()) {
              LOG(ERROR) << "\tRunning model failed: " << run_status << "\n";
              return -1;
        }

        //cout << outputs[0].DebugString() << endl;
        for (auto output: outputs) {
            cout << output.DebugString() << endl;
        }
        cout << "TensorFlow End" << endl;

I am getting the following output:2018-12-12 14:02:22.762529: E ..\TensorsampleGit\main.cpp:74] Running model failed: Not found: FeedInputs: unable to find feed output input:0

Reference github:https://github.com/davidsandberg/facenet/issues/357

Comments