报错信息:AttributeError: 'NoneType' object has no attribute '_inbound_nodes' #11811
解决方案:
1. 原因:keras形成model的流程中必须要全部用开头为大写的层结构。例如:Concatenate(),所有keras.backend下面的功能性function都应该被封装成层结构。
The problem is that squeezed_cat_conv2 is not the output of a keras layer. You should put squeeze
in a lambda layer. You can use keras layers on normal tensors, but if you want to make a Model
all operations should be in keras layers.
The concatenate()
is an operation which can be performed on tensors. The Concatenate()
is a layer. Which should be used as such. So I was wrong before, you should use:cat_conv = Concatenate(axis=3)([conv2d_out7,conv2d_out6,conv2d_out5])
Where you first construct the layer with Concatenate(axis=3)
and then call it with the inputs of the layer.
2. 方法: 把tensor操作function封装在Lambda自定义层结构中。
you have forgotten to wrap expand_dims
inside a Lambda
layer as well:
sent_input = Lambda(lambda x: expand_dims(x, axis=3))(sent_embed) # for channels