在张量流示例中,feed_dict用于将训练或验证输入发送到同一模型图中.很遗憾,您无法提供申请人:
Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.
Run Code Online (Sandbox Code Playgroud)
我一直在使用输入管道TFRecordReader,所以我的数据永远不会真正进入python.不得不调用run将数据导入python只是为了将其反馈到tensorflow似乎很愚蠢,而且肯定很慢.
有没有人有这个很好的解决方案?
目前,我只是创建两个使用相同参数的模型子图的相同副本.这有效,但迫使我以奇怪的方式组织我的代码.
编辑
例如,我目前正在做类似的事情:
model_params = BuildModelParams()
train_model = BuildModel(model_params, train_input)
test_model = BuildModel(model_params, test_input)
Run Code Online (Sandbox Code Playgroud)
以便测试模型使用训练学到的参数.好处feed_dict是我只需要定义一次模型,我不必将模型的参数与其结构分开.
当涉及输入队列时,此解决方案可能会导致严重问题.请参阅:https://groups.google.com/a/tensorflow.org/forum/#!msg/discuss/mLrt5qc9_uU/sGNbC7GpAwAJ
感谢@fwalch在评论中指出这一点
没有办法完全按照你的要求去做,请在这里查看我的问题的答案.
但是0.7版的新公开" cond "可以填满你的用例:
# Here are the two data streams.
train_data = tf.Variable(999)
test_data = tf.Variable(1000)
# This selects which stream to use.
select_test = tf.placeholder(dtype=bool,shape=[],name='select_test')
data = tf.cond(
select_test,
lambda:test_data,
lambda:train_data
)
# Here is the model.
model = data-500;
init = tf.initialize_all_variables()
with tf.Session():
init.run()
# You just have to feed `select_test` when you evaluate the model.
print(model.eval({select_test:False})) #499
print(model.eval({select_test:True})) #500
Run Code Online (Sandbox Code Playgroud)
您可以使用相同的技巧切换批量标准化以在测试期间使用移动平均值.
| 归档时间: |
|
| 查看次数: |
1486 次 |
| 最近记录: |