gpt4 book ai didi

python - 对象没有属性 'inbound_nodes'

转载 作者:行者123 更新时间:2023-11-28 17:16:22 25 4
gpt4 key购买 nike

我正在尝试定义一个模型并对其进行编译,但由于某种原因我无法编译或定义该模型...

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'

错误似乎是在定义网络的输入和输出时发生的。我不确定为什么。卷积和池化都是为了处理输入而设计的。所以这个错误对我来说毫无意义?

最佳答案

有点晚了,但我刚刚遇到了类似的问题,我想其他人可能也有类似的问题。我认为你弄错的是:

out = out + output_convolution[column][row]

尝试将其更改为:

out = add([out, output_convolution[column][row]]))

addkeras.layers.merge 中。与 tensorflow 不同,keras 似乎无法将 a+b 解释为图中的节点,因此它会刹车。

另外,为了将来引用,我尝试做的是减去两个张量 (a - b),如下所示:

subt = add([a, -b])

这引发了同样的异常。我的做法是将 b 定义为 -b,虽然不花哨,但确实有效。

关于python - 对象没有属性 'inbound_nodes',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43879735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com