小编DrB*_*BBQ的帖子

使用TF_SessionRun在C(不是C++)中运行TensorFlow图时的分段错误

我正在尝试使用C API加载和运行TensorFlow图形(我需要在TensorFlow项目之外构建,最好不使用Bazel,因此不能使用C++).

该图是3层LSTM-RNN,其将3个元素的特征向量分类为9个类中的一个.该图是用Python构建和训练的,我在Python和C++中都进行了测试.

到目前为止,我已经加载了图形,但是在加载图形后我无法运行会话.我已经做了很多挖掘,但我只发现了一个使用C API的例子(这里),并且不包括运行图形.

我已经设法将以下内容放在一起,但它产生了一个分段错误(如果我注释掉TF_SessionRun()调用,我可以成功运行代码,但是当包含TF_SessionRun()时我得到seg错误).这是代码:

#include "tensorflow/c/c_api.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <iterator>


TF_Buffer* read_file(const char* file);

void free_buffer(void* data, size_t length) {
        free(data);
}

static void Deallocator(void* data, size_t length, void* arg) {
        free(data);
}

int main() {
  // Use read_file to get graph_def as TF_Buffer*
  TF_Buffer* graph_def = read_file("tensorflow_model/constant_graph_weights.pb");
  TF_Graph* graph = TF_NewGraph();

  // Import graph_def into graph
  TF_Status* status = TF_NewStatus();
  TF_ImportGraphDefOptions* graph_opts = …
Run Code Online (Sandbox Code Playgroud)

c tensorflow

6
推荐指数
1
解决办法
3835
查看次数

标签 统计

c ×1

tensorflow ×1