TensorFlow的目标剪枝找不到节点

TensorFlow's target pruning can't find nodes

我使用 TensorFlow API 编写了一个 Python 脚本,其中包括一个转储图形定义的 SummaryWriter 以便我可以在 TensorBoard 中查看它。

当 运行 脚本时,抛出一个 NotFoundErrorPruneForTargets: Some target nodes not found: Reading/data_queue_EnqueueMany_1。顾名思义,该节点是通过对 FIFOQueueenqueue_many 调用创建的(然后在 QueueRunner 中启动);它确实存在,并且可以在 TensorBoard 中清楚地看到。

什么会导致 TensorFlow 找不到某些节点?

这是一个已知问题,当您在向图表添加更多节点之前启动访问 TensorFlow 图表的线程(例如您的 QueueRunner)时会发生此问题。 (底层 tf.Graph 数据结构对于并发读写不是线程安全的。)

解决方案是在调用 start_queue_runners() 之前立即移动 tf.train.start_queue_runners(sess) (and any other code that starts threads) after the last node is constructed. One way to double-check this is to add a call to tf.get_default_graph().finalize()