我正在尝试定义一个模型来编译它,但我出于某种原因无法编译或定义此模型......
def fws():
filter_size = 8
pooling_size = 6
stride_step = 2
J = 80
splits = 33
total_frames_with_deltas = 45
pool_splits = ((splits - pooling_size)+1)/2
print "pool_splits" + str(pool_splits)
print "Printing shapes"
list_of_input = [Input(shape=(8,3)) for i in range(splits*total_frames_with_deltas)]
output_convolution = []
for steps in range(total_frames_with_deltas):
conv = Conv1D(filters = J, kernel_size = 8)
column = 0
skip = 45
conv_output = []
for _ in range(splits):
conv_output.append(conv(list_of_input[(column*skip)+steps]))
column = column + 1
output_convolution.append((conv_output))
print len(output_convolution)
print len(output_convolution[0])
out = 0
output_conv = []
for row in range(splits):
for column in range(total_frames_with_deltas):
#print row
#print column
out = out + output_convolution[column][row]
output_conv.append(out)
output_con = Concatenate()(output_conv)
output_con = Reshape((splits,-1))(output_con)
pooled = MaxPooling1D(pool_size = pooling_size, strides = stride_step)(output_con)
print pooled.shape
#reshape = Reshape((3,-1))(pooled)
#fc
dense1 = Dense(units = 1000, activation = 'relu', name = "dense_1")(pooled)
dense2 = Dense(units = 1000, activation = 'relu', name = "dense_2")(dense1)
dense3 = Dense(units = 50 , activation = 'softmax', name = "dense_3")(dense2)
raw_input("Model definition ok!")
model = Model(inputs = list_of_input , outputs = dense3)
raw_input("Model definition with input/output")
model.compile(loss="categorical_crossentropy", optimizer='sgd' , metrics = [metrics.categorical_accuracy])
这是完整的错误消息:
File "keras_cnn_phoneme_original_fit_generator.py", line 231, in <module>
fws()
File "keras_cnn_phoneme_original_fit_generator.py", line 212, in fws
model = Model(inputs = list_of_input , outputs = dense3)
File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1676, in __init__
build_map_of_graph(x, finished_nodes, nodes_in_progress)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1666, in build_map_of_graph
layer, node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1666, in build_map_of_graph
layer, node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1666, in build_map_of_graph
layer, node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1666, in build_map_of_graph
layer, node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1666, in build_map_of_graph
layer, node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1664, in build_map_of_graph
next_node = layer.inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
定义网络的输入和输出时似乎发生错误。 我不知道为什么..卷积和池的设计都是为了处理输入..所以错误对我来说没有意义?
答案 0 :(得分:2)
有点晚了,但我遇到了类似的问题,我猜其他人也可能有类似的问题。我认为你错的是:
out = out + output_convolution[column][row]
尝试将其更改为:
out = add([out, output_convolution[column][row]]))
add
位于keras.layers.merge
的位置。
与张量流不同,keras似乎无法将a+b
解释为图中的节点,因此它会制动。
同样为了将来的参考,我试图做的是减去两个张量(a - b
),如下所示:
subt = add([a, -b])
引发同样的例外。我这样做的方法是将b
定义为-b
,而不是花哨但它有效。