我有一個在 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:圖無法按拓撲順序排序。
uj5u.com熱心網友回復:
不確定您要做什么,但應該可以:
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://www.uj5u.com/ruanti/508265.html
上一篇:沒有為任何變數誤差提供梯度
