天天看点

Keras报错AttributeError ’NoneType‘ object has no attribute ‘_inbound_nodes’

        在使用Keras实现网络结构时,报错AttributeError: ‘NoneType’ object has no attribute ‘_inbound_nodes’

出现这个报错提示的原因:

keras构建网络结构时采用layers

Keras报错AttributeError ’NoneType‘ object has no attribute ‘_inbound_nodes’

而一些操作可能导致存在非layers

如:

Keras报错AttributeError ’NoneType‘ object has no attribute ‘_inbound_nodes’

这里的 branchB * branchC 不是layers的类型,可以改为 keras.layers.Multiply()([branchB, branchC])

如:

在层中直接使用:

from keras import backend as K
K.mean(input, axis=3, keepdims=True)
           

可以用keras.layers.Lambda构造层

from keras.layers import Lambda
Lambda(lambda x: K.mean(x, axis=3, keepdims=True))(input)
           

继续阅读