在修改源碼是出現以下錯誤,此時是要往代碼里加入attention機制,在網絡的構建中,混合了sonnet跟tensorflow(菜,改不動別人的源碼),所以在修改代碼時出現了以下錯誤。
ValueError: Trainable variable created when calling a template after the first time, perhaps you used tf.Variable when you meant tf.get_variable
解決方法:
在此前的代碼中,tf.layers.Conv2D()與sonnet中的MLP是可以正常連接的,所以想到可能tf.keras.layers.XXX與tf.layers.XXX具體實現不同,故做以下修改:
將上述
a = tf.keras.layers.Dense(timesteps, activation='softmax' )(a)
改爲:
a = tf.layers.Dense(timesteps, activation='softmax' )(a)
即可正常運行