运行tensorflow训练模型c ++的错误

时间:2017-03-31 07:46:03

标签: c++ tensorflow

我正在研究Tensorflow on c ++,我自己训练网络。我在MS-Celeb-1M上训练了facenet,然后创建了我的graph.pb。我修改了此处提供的示例:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/label_image以测试我的网络。

在main.cpp中:

string graph = "data/graph1.pb";
string output_layer = "InceptionResnetV1/Repeat/block35_5/Relu";

如果我测试,我会收到此错误:

Running model failed: Invalid argument: You must feed a value for placeholder tensor 'phase_train' with dtype bool [[Node: phase_train = Placeholderdtype=DT_BOOL, shape=[], _device="/job:localhost/replica:0/task:0 /cpu:0"]]

我已经找到了一些答案,例如https://github.com/davidsandberg/facenet/issues/108

  

但仍有问题

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'phase_train' with dtype bool
     

初始化全局变量时。我不确定为什么会出现这个问题,但它与批量规范化有关。可以通过更改

来修复
phase_train_placeholder = tf.placeholder(tf.bool, name='phase_train')
     

phase_train_placeholder = tf.placeholder_with_default(tf.convert_to_tensor(True, dtype=tf.bool), shape=(), name='phase_train')
     

然后它似乎工作正常。

大卫桑德伯格谈到改变一条线。但是,我不知道如何在c ++中提供参数phase_train

1 个答案:

答案 0 :(得分:0)

当你调用Session-> Run时,方法的第一个输入是pair的向量。你需要创建一个名为phase_train的张量,输入布尔值,以及任何有意义的值。将该张量添加到输入列表中。