serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
779 stars 177 forks source link

Can you provide a tf.example as input example? #193

Open hudengjunai opened 2 years ago

hudengjunai commented 2 years ago

Thank you for your cppflow lib. I'm integrated this lib in my inference server. but I encountered some problem.

my model is like this

 MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['examples'] tensor_info:
        dtype: DT_STRING
        shape: (-1)
        name: input_example_tensor:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['prob'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1)
        name: Sigmoid:0
  Method name is: tensorflow/serving/predict

so how can I call like below

  TF_TString tstr[16];
    int in_index=0;
    for (const auto &sample : section) {
      TF_TString_Init(&tstr[in_index]);
      TF_TString_Copy(&tstr[in_index], sample.c_str(), sample.size());
      //sample = tf.example.Serializetotring();
      in_index++;
    }

    int item_count = section.size();
    TF_Tensor
        *tf_tensor = TF_NewTensor(TF_STRING, nullptr, 0,  &tstr[0], section.size(), deallocator, nullptr);
    cppflow::tensor cp_tensor = cppflow::tensor(tf_tensor);
    inputs.push_back(std::make_tuple("input_example_tensor:0"s, cp_tensor));

but encuntered some problem  So, my question is ." how can I set tf.Example as input for cppflow", I want some examples code or snippet code to solve it. thanks.

hudengjunai commented 2 years ago

Thank you for your cppflow lib. I'm integrated this lib in my inference server. but I encountered some problem.

my model is like this

 MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['examples'] tensor_info:
        dtype: DT_STRING
        shape: (-1)
        name: input_example_tensor:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['prob'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1)
        name: Sigmoid:0
  Method name is: tensorflow/serving/predict

so how can I call like below

  TF_TString tstr[16];
    int in_index=0;
    for (const auto &sample : section) {
      TF_TString_Init(&tstr[in_index]);
      TF_TString_Copy(&tstr[in_index], sample.c_str(), sample.size());
      //sample = tf.example.Serializetotring();
      in_index++;
    }

    int item_count = section.size();
    TF_Tensor
        *tf_tensor = TF_NewTensor(TF_STRING, nullptr, 0,  &tstr[0], section.size(), deallocator, nullptr);
    cppflow::tensor cp_tensor = cppflow::tensor(tf_tensor);
    inputs.push_back(std::make_tuple("input_example_tensor:0"s, cp_tensor));

but encuntered some problem  So, my question is ." how can I set tf.Example as input for cppflow", I want some examples code or snippet code to solve it. thanks.

ns-wxin commented 2 years ago

Did you get any response? Your question is similar to mine which is about creating DT_STRING tensor. Also my address sanitizer is complaining memory leak on the way the DT_STRING tensor is created on the function "TF_TString_Copy()".

hudengjunai commented 2 years ago

No, I'am trying use compiled tensorflow_cc.so directly from tensorflow-source. and use the tf c++ header and lib.

RUN cd tensorflow-1.15.0 && ./configure && \
        bazel build  //tensorflow/tools/pip_package:build_pip_package && \
        bazel build //tensorflow:libtensorflow_cc.so && \
        bazel build --config=opt tensorflow:install_headers

After compiled the libtesorflow_cc.so lib and header files. Encountered some protobuf version problem. with grpc-server. So I delay this feature for my project.

Did you get any response? Your question is similar to mine which is about creating DT_STRING tensor. Also my address sanitizer is complaining memory leak on the way the DT_STRING tensor is created on the function "TF_TString_Copy()".

serizba commented 1 year ago

Hi,

So, the problem is about how to create a proper TF_TString tensor, right?