问题:
topological sort failed with message: The graph couldn’t be sorted in topological order.
背景:
我确认自己的建立的图没有环,但是运行的时候tensorflow会报graph中存在非拓扑结构
原因:
使用n卷积,每个卷积的输入都是相同的数据data,这样会得到n个卷积结果,然后按axis=3的维度进行合并,这个时候会报错。
解决方案:
不要在最后将n个卷积结果一次性的合并,而是要在每次卷积后与之前的卷积进行合并。
# Negative samples
# import data: dt, output: result
nn_res = []
for i in range(10):
tmp = tf.layers.conv2d(dt, 9, 3, 1, padding='same', acivation=tf.nn.relu)
nn_res.append(tmp)
result = tf.concat(nn_res, axis=-1)
# topological sort failed with message: The graph couldn't be sorted in topological order
# Positive samples
# import data: dt, output: result
result = 0
for i in range(10):
tmp = tf.layers.conv2d(dt, 9, 3, 1, padding='same', acivation=tf.nn.relu)
result = tmp if i == 0 else tf.concat([result, tmp], axis=3)
# there is no problem
感谢老哥的博客:
https://blog.csdn.net/qq_35240640/article/details/105331372