我在Tensorflow (使用Keras)中创建了一个模型。
在伪代码中,没有过多地编写特定于数据的操作操作,大致是:
iter_count = tf.keras.layers.Dense(1)(input)
#scale iter_count between 1 and int_max
for i in tf.range(iter_count):
inputvariation = tf.concat([input, i])
box = tf.keras.layers.Dense(4)(inputvariation)
#append to TensorArray
#stack and return TensorArray
然而,这输出了一个错误,无法将模型按拓扑顺序排序。这是否意味着我不能在我的模型中运行循环?
一些错误:
E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:771]迭代= 0,拓扑排序失败的消息:图不能按拓扑顺序排序。
W tensorflow/core/common_runtime/process_function_library_runtime.cc:941]忽略多设备功能优化失败: INVALID_ARGUMENT:图不能按拓扑顺序排序.
发布于 2022-09-13 05:44:47
不确定你想做什么,但这应该是可能的:
import tensorflow as tf
inputs = tf.keras.layers.Input((5, ))
iter_count = tf.keras.layers.Dense(1)(inputs)
for i in tf.range(tf.shape(iter_count)[-1]):
# if you want to get the actual output of the Dense layer **iter_count**
# try i = itercount[:, i]
inputvariation = tf.concat([inputs, tf.cast(tf.repeat(i, repeats=tf.shape(inputs)[0])[..., None], dtype=tf.float32)], axis=-1)
box = tf.keras.layers.Dense(4)(inputvariation)
model = tf.keras.Model(inputs, box)
model(tf.random.normal((1, 5)))
https://stackoverflow.com/questions/73695848
复制相似问题