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)
這樣就不會出錯了.