2

我试图在加载保存的模型时抑制 C-API 中张量流的日志记录。日志看起来像这样

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.

下面是我加载保存模型的代码部分

    //*********************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);

由于关于 TF C-API 的文档很少,我现在陷入了这个问题。有人知道怎么做吗?

4

1 回答 1

2

经过一番努力,我找到了一种方法,方法是设置一个名为 TF_CPP_MIN_LOG_LEVEL 的新环境变量。我是这样做的:

#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

}

我通过结合https://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.htmlDisable Tensorflow 调试信息得到了答案

干杯! 希望这对那些像我一样面临同样头痛的人有所帮助。

菲尔

于 2020-07-31T01:24:48.303 回答