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


問題說明:

首先呢,報這個錯誤的代碼是這行代碼:

model = Model(inputs=input, outputs=output)

報錯:

 AttributeError 'NoneType' object has no attribute '_inbound_nodes'

解決問題:

本人代碼整體采用Keras Function API風格,其中使用代碼中使用了concatenate以及reshape這兩個方法,具體使用:

from keras import backend as K
from keras.layers import Dense, Input

inpt = Input(shape=(224, 224, 3))
x = Conv2d(63, (3,3), padding='same', activation='relu')
...
x = K.concatenate([branch1, branch2, branch3], axis=3)
x = K.reshpe(x, (1000,))
# 上面兩行代碼並不是連續出現,這里寫出來,主要描述使用了“連接”“reshape”兩種操作;

或許,在你的代碼中也存在這兩行代碼,又或者使用了類似的一些方法,問題就出在這里:

x = K.concatenate([branch1, branch2, branch3], axis=3)
x = K.reshpe(x, (1000,))

將之修改為:

from keras.layers import Concatenate, Resahpe

x = Concatenate(axis=3)([branch1, branch2, branch3])
x = Resahpe((1000,))(x)

可以想到,直接使用concatenate或者reshape不是作為一層,而Concatenate或者Reshape是一個layer;

那么,類似的錯誤都可以按照這個思路來檢查代碼吧。


免責聲明!

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



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