图形无法按拓扑顺序排序

图形无法按拓扑顺序排序

本文介绍了Tensorflow 警告:图形无法按拓扑顺序排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 tensorflow 训练(使用自定义图形,闭源)时,它输出警告:

When I run tensorflow training (with custom defined graph, closed source), it outputs the warning:

2018-10-03 14:29:24.352895: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:666] Iteration = 0, topological sort failed with message: The graph could not be sorted in topological order.

什么意思?什么可能导致此问题以及如何避免它?

What does it mean? What could likely cause this problem and how to avoid it?

更新: 作为记录,就我而言,尽管有此警告,tensorflow 仍然可以正常工作.所以我认为这只是意味着计算图中的循环比 tensorflow 预期的要多,不一定是无限循环.我通过避免在代码中使用手动循环来解决这个问题,而是使用张量操作(stack、concat、slice、reshape...)

Update: For the record, in my case, tensorflow still works correctly despite this warning. So I think it just means there are more loops in the computation graph than what tensorflow expects, not necessarily infinite loop. I fixed this by avoid using manual loop in code, but instead using tensor manipulation (stack, concat, slice, reshape...)

推荐答案

A 拓扑排序一个有向图是它的顶点的一种排序方式,只要有一条从顶点 u 到顶点 v 的边,顶点 u 就会出现在排序中的顶点 v 之前.

A topological ordering of a directed graph is an ordering of its vertices in such a way that whenever there is an edge from vertex u to vertex v, vertex u comes before vertex v in the ordering.

这种排序适用于每个有向无环图,但不适用于任意图.您的图中很可能存在某种阻止排序算法成功的循环.因此,要走的路是寻找循环并以某种方式将其删除.

This kind of ordering is possible for every directed acyclic graph but not for arbitrary graphs. There is most likely some kind of cycle in your graph that prevents the sorting algorithm from succeeding. So, the way to go is searching for the cycle and removing it in some way.

举个例子,考虑一个非常小的图,它有两个顶点,uv,还有两条边,u ->vv ->u.没有办法按照上面给出的要求对 u 和 v 进行排序.

As an example, consider a very small graph with two vertices, u and v, and two edges, u -> v and v -> u. There is no way to sort u and v in accordance with the requirements given above.

如果没有关于您的代码的更多信息,就很难准确说明发生了什么.

Without further information on your code it is hard to say exactly what is going on.

这篇关于Tensorflow 警告:图形无法按拓扑顺序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:59