PatWie / tensorflow-cmake

TensorFlow examples in C, C++, Go and Python without bazel but with cmake and FindTensorFlow.cmake
Apache License 2.0
439 stars 91 forks source link

C- How to pass img file in tensorflow graph (tf c_api) #32

Closed Ashokcharu closed 5 years ago

Ashokcharu commented 5 years ago

I used the tensorflow(python) model to train face images and I got good results in detection.

After trained images in the tensorflow(python), I got .PB file, Using this PB file I want to implement face detection in C.

I saw your project in GitHub and I'm using that.

I Had configured tensorflow c api and opencv in my project,

Now I don't know, how to pass image file in tensorflow graph. I checked your c++ resize example also, but i did not get any idea.

PatWie commented 5 years ago

This is a quite broad question. Please, reconsider if you really need to use plain C instead of C++. To read an image in C I suggest using FreeImage which is totally unrelated to this git project.

Then it is basically adjusting everything around

TF_Tensor* input_tensor =
      TF_NewTensor(TF_FLOAT, raw_input_dims, 2, raw_input_data,
                   2 * sizeof(float), &deallocator, NULL);

does the job. You need to be more specific .

Ashokcharu commented 5 years ago

Thanks for your quick reply

This is how i loaded my image file using opencv

  IplImage* img = cvLoadImage("/home/cll/ai/sample/arya.jpg", CV_LOAD_IMAGE_COLOR);

  if (!img)
  {
    printf("Image can NOT Load!!!\n");
    return 1;
  }

Now my question is, How can I pass the img variable to tensorflow graph.

In below input_tensor where can I pass the img variable.

TF_Tensor* input_tensor =
      TF_NewTensor(TF_FLOAT, raw_input_dims, 2, raw_input_data,
                   2 * sizeof(float), &deallocator, NULL);

Thanks Advance

PatWie commented 5 years ago

You will need to access the underlying image buffer of img and cast it eventually to float. This is an OpenCV questions rather than related to this repository.