Tensorflow C API占位符/输入变量设置

安德烈亚斯·格拉夫(Andreas Graf)

我正在尝试使用TensorFlow C-API运行已从Keras / TF模型保存的LeNet的实现,但是在设置输入时遇到了一致的问题。相关的代码段是:

  // Load the image with openCV
  CvMat * img = cvLoadImageM(argv[1], CV_LOAD_IMAGE_COLOR );

  // Create an Tensor from the image
  int64_t dims4[]={1,1,28,28};
  TF_Tensor * imgTensor = TF_NewTensor(TF_FLOAT,dims4,4,img,28*28*sizeof(float),NULL,NULL);


  TF_Operation* init_op2 = TF_GraphOperationByName(graph, "conv2d_1_input");
  TF_Operation* targets[] = {init_op2};

  // Build up the inputs
  TF_Output inp = {
          init_op2,
          0
  };
  TF_Output * inputs[] = {&inp};
  TF_Tensor * input_values[] = {imgTensor};

  printf("\nBefore\n");
  TF_SessionRun(session, NULL,
                &inp, inputvalues, 1,  // inputs
               NULL, NULL, 0,  // outputs
                &init_op2, 1,    // targets
                NULL,
                status);
  printf("After\n");
  printf("Status %d %s\n", TF_GetCode(status), TF_Message(status));

但是,无论如何,我尝试建立输入张量,但得到错误状态和消息:

Status 3 You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float and shape [?,1,28,28]
     [[Node: conv2d_1_input = Placeholder[_output_shapes=[[?,1,28,28]], dtype=DT_FLOAT, shape=[?,1,28,28], _device=...]()]]

对我做错了什么建议吗?

在对的调用中TF_SessionRun,您还提供了conv2d_1_input作为“目标”操作。该错误消息可以得到改善,但基本上是在抱怨您要会话执行占位符操作,该操作不能执行-这是不可能的(请参阅文档中的注释tf.placeholder)。

您是否应该从呼叫中索取不同的targetoutput张量,TF_SessionRun例如:

TF_Output out = { TF_GraphOperationByName(graph, "<name_of_output_tensor>"), 0 };

TF_Tensor* outputvalues = NULL;
TF_SessionRun(session, NULL,
              &inp, inputvalues, 1,  // inputs
              &out, &outputvalues, 1,  // outputs
              NULL, 0,  // targets
              NULL, status);

希望能有所帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Tensorflow Java API为分类列设置了占位符

在 Tensorflow C++ API 中为占位符张量提供值

输入占位符时TensorFlow InvalidArgumentError

如何设置Tensorflow Lite C ++的输入

Tensorflow占位符形状

Tensorflow:占位符的InvalidArgumentError

TensorFlow C API 日志记录设置

训练后用占位符交换TensorFlow数据集输入管道

tensorflow InvalidArgumentError:“您必须输入占位符张量的值”

如何正确将数组输入TensorFlow占位符

在 tensorflow 中使用公共输入对占位符进行分组

无法在tensorflow中使用占位符初始化变量

如何在 C 中的字符串中设置变量占位符

Tensorflow模型占位符还原

用于动态输入形状的 Tensorflow C++ API

Tensorflow C++ API 分配变量值

TensorFlow Lite C ++ API示例进行推理

如何使用C API遍历Tensorflow图?

Google Cloud TPU对Tensorflow C ++ API的支持

为可变大小和固定大小的输入创建TensorFlow占位符有什么缺点吗?

Tensorflow:您必须使用dtype float [但该值是float]来输入占位符张量“ Placeholder”的值

Tensorflow-您必须使用dtype float来输入占位符张量'X'的值

TensorFlow类的占位符以及其他定义输入张量的方法

使用tf.cond()时,Tensorflow要求输入不必要的占位符

将 numpy uint8 输入 tensorflow float32 占位符

Tensorflow占位符vs Tensorflow常数vs numpy数组

替换Tensorflow v2的占位符

检查tensorflow占位符是否已填充

Tensorflow用数组填充占位符