简体   繁体   English

TensorFlow C API 记录设置

[英]TensorFlow C API Logging Setting

I am trying to suppress the logging of the tensorflow in C-API when it loads a saved model.当加载保存的 model 时,我试图在 C-API 中抑制 tensorflow 的日志记录。 The logging looks like this日志看起来像这样

2020-07-24 13:06:39.805191: I tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: /home/philgun/tf-C-API/my_model
2020-07-24 13:06:39.806627: I tensorflow/cc/saved_model/reader.cc:54] Reading meta graph with tags { serve }
2020-07-24 13:06:39.819994: I tensorflow/cc/saved_model/loader.cc:202] Restoring SavedModel bundle.
2020-07-24 13:06:39.875249: I tensorflow/cc/saved_model/loader.cc:151] Running initialization op on SavedModel bundle at path: /home/philgun/tf-C-API/my_model
2020-07-24 13:06:39.884401: I tensorflow/cc/saved_model/loader.cc:311] SavedModel load for tags { serve }; Status: success. Took 79210 microseconds.

Below is the part of my code that loads the saved model下面是我加载保存的 model 的代码部分

    //*********************Read Model
    TF_Graph* Graph = TF_NewGraph();
    TF_Status* Status = TF_NewStatus();

    TF_SessionOptions* SessionOpts = TF_NewSessionOptions();
    TF_Buffer* RunOpts = NULL;

    const char* tags = "serve"; // default model serving tag
    int ntags = 1;
    
    TF_Session* Session = TF_LoadSessionFromSavedModel(SessionOpts, RunOpts, saved_model_dir, &tags, ntags, Graph, NULL, Status);

Since there's so little documentation on TF C-API, I am now stuck in this problem.由于关于 TF C-API 的文档很少,我现在陷入了这个问题。 Does anybody know how to do it?有人知道怎么做吗?

After some hustling I found a way to do it by setting a new environment variable called TF_CPP_MIN_LOG_LEVEL.经过一番努力,我找到了一种方法,方法是设置一个名为 TF_CPP_MIN_LOG_LEVEL 的新环境变量。 Here's how I did it:我是这样做的:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tensorflow/c/c_api.h"

int main()
{
    <your main code>
}

void CallSavedModel(double raw_input[], int inputsize, char* saved_model_dir)
{
     char* new_environment = "TF_CPP_MIN_LOG_LEVEL=3";
     int ret;
     ret = putenv(var);

     IMPORT YOUR SAVED MODEL START FROM HERE

}

I got the answer by combining https://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.html and Disable Tensorflow debugging information我通过结合https://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.html禁用 ZCB20B802A3F0255E054E4FB82 调试信息得到了答案

Cheers.干杯。 Hope this is helpful for those who faced the same headache like I had.希望这对那些像我一样面临同样头痛的人有所帮助。

Phil菲尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM