使用Lambda解決_inbound_nodes錯誤


Keras出現了下面的錯誤:

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

原因是使用了Keras backend的reshape操作:

x = K.reshape(x, (num_pictures, 32, 32, 512))

但是Keras backend並不是一個Layer,於是出現了上面的錯誤.解決的方法是使用Lambda,Lambda用於定義一個Layer,其中沒有需要學習的變量,只是對Tensor進行一些操作.先定義一個reshape的函數:

def reshape_tensor(x, shape):
    return K.reshape(x, shape);

然后再調用這個函數:

x = Lambda(reshape_tensor, arguments={'shape': (num_pictures, 32, 32, 512)})(x)

這樣就不會出錯了.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM