我为CNN制作了具有多渠道的模型。 但是输入只是我的代码中显示的内容。 我收到一个错误:AttributeError:'NoneType'对象没有属性'_inbound_nodes' 我看到了其他人的回答,但是我没有使用任何重复向量。
def ensemble(x_train):
model_input = input_part(x_train)
x = Conv1D(6, 5, activation='relu')(model_input)
conv_pool_model = conv_pool(x) #this is a CNN model
x_train_1 = x[ : , :227, : ]
x_train_2 = x[ :, 227:454, : ]
x_train_3 = x[ :, 454:680, : ]
x_train_4 = x[ :, 680: , : ]
# there are four part CNN.
cnn_p1_model = cnn_p1(x_train_1)
cnn_p2_model = cnn_p1(x_train_2)
cnn_p3_model = cnn_p1(x_train_3)
cnn_p4_model = cnn_p1(x_train_4)
conca = Concatenate(axis=1)([conv_pool_model, cnn_p1_model, cnn_p2_model, cnn_p3_model, cnn_p4_model])
x_out = Dropout(0.5)(conca)
x_out = Dense(2, activation='softmax')(x_out)
model = Model(inputs = model_input, outputs=x_out, name='conv_pool_cnn')
return model
这是错误提示:
Traceback (most recent call last):
File "D:/Users/11825/source/repos/mutil cnn/hope.py", line 192, in <module>
cnn_pool_model = ensemble(x_train)
File "D:/Users/11825/source/repos/mutil cnn/hope.py", line 58, in ensemble
model = Model(inputs = model_input, outputs=x_out, name='conv_pool_cnn')
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 93, in __init__
self._init_graph_network(*args, **kwargs)
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 231, in _init_graph_network
self.inputs, self.outputs)
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 1366, in _map_graph_network
tensor_index=tensor_index)
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 1353, in build_map
node_index, tensor_index)
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 1353, in build_map
node_index, tensor_index)
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 1353, in build_map
node_index, tensor_index)
[Previous line repeated 10 more times]
File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\keras\engine\network.py", line 1325, in build_map
node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
答案 0 :(得分:0)
Keras层的输入必须是其他Keras层的直接输出。因此,您还需要在图层中进行切片。您可以为此目的使用Lambda
层:
x_train_1 = Lambda(lambda x: x[ : , :227, : ])(x)
x_train_2 = Lambda(lambda x: x[ :, 227:454, : ])(x)
x_train_3 = Lambda(lambda x: x[ :, 454:680, : ])(x)
x_train_4 = Lambda(lambda x: x[ :, 680: , : ])(x)