close

undefined

使用 tf.estimator.inputs.numpy_input_fn 與 tf.keras.estimator.model_to_estimator 時遇到下述的問題:

ValueError: Cannot find input with name "xxx" in Keras Model. It needs to match one of the following: input_1

才發現 tf.estimator.inputs.numpy_input_fn 使用的字典檔 key 值需要跟 Input Layer 的名稱相同,換句話說, Input Layer 需要給個名字才行。

如下所示:

input_layer1 = tf.keras.layers.Input(shape=(vocab_size,),name='post')

...

def input_function(features,labels,shuffle=False):
    input_fn = tf.estimator.inputs.numpy_input_fn(
        x={'post': features},
        # x=features,
        y=labels,
        shuffle=shuffle
    )
    return input_fn

這兩個欄位要搭配起來(綠色部分)才不會出現上述的錯誤。

arrow
arrow
    全站熱搜

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()