【问题标题】:TensorFlow C API Logging SettingTensorFlow C API 日志记录设置
【发布时间】:2020-11-13 21:17:53
【问题描述】:

当加载保存的模型时,我试图禁止在 C-API 中记录 tensorflow。日志如下所示

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 的文档很少,我现在陷入了这个问题。有人知道怎么做吗?

【问题讨论】:

    标签: c tensorflow c-api tensorflow-c++


    【解决方案1】:

    经过一番努力,我找到了一种方法,方法是设置一个名为 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 debugging information得到了答案

    干杯! 希望这对那些和我一样头疼的人有所帮助。

    菲尔

    【讨论】:

    猜你喜欢
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    • 2023-03-23
    • 2019-10-10
    • 2011-07-23
    • 2012-09-24
    • 2022-01-27
    相关资源
    最近更新 更多