Я пытаюсь объединить слои из моей модели, но получаю сообщение об ошибке, и я проверил решение для ошибки в StackOverflow, но не смог реализовать в своем коде.
Я пытался реализовать tf.concat()
и keras.layers.Concatenate
, но для них также я получил ошибку типа NoneType
, у объекта нет атрибута _inbound_nodes
.
# Define the model
def my_model(input_shape, output):
if K.image_dim_ordering() == 'tf':
input_shape= (input_shape[1], input_shape[2], input_shape[0])
input = Input(input_shape)
conv_1 = bn_conv(32, (3,3), 1, padding="same")(input) #RF-3
#conv_2 = bn_conv(48, (3,3), 1, padding="same")(conv_1) #RF-5
#conv_3 = bn_conv(64, (3,3), 1, border_mode="same")(conv_2) #RF-7
conv_4 = bn_conv(32, (1,3), 1, padding = "same")(conv_1)
conv_5 = bn_conv(64,(3,1), 1, padding = "same")(conv_4) #RF-7
skip1 = space_to_depth_x2(conv_5)
conv_6 = keras.layers.SeparableConv2D(filters = 128, kernel_size = (3,3),
strides= 1, padding = "same")(conv_5)
conv_7 = bn_conv(128, (1,1), 1, padding = "same")(conv_6) # RF-9
skip2 = space_to_depth_x2(conv_7)
max_1 = MaxPooling2D((2,2),2)(conv_7) #RF-18, size - 16
conv_8 = bn_conv(128, (1,1), 1)(max_1)
#skip3 = space_to_depth_x3(conv_8)
#E_merge = merge([skip1, skip2, conv_8], mode = "concat", concat_axis =-1)
E_merge = concatenate([skip1, skip2, conv_8], axis=-1)
conv_g1 = bn_conv(32, (1,1),1, padding="same")(E_merge)
conv_g2 = bn_conv(64, (3,3),1, padding = "same")(conv_g1)# RF - 20
conv_g3 = bn_conv(32, (1,1), 1, padding = "same")(E_merge)
conv_g4 = bn_conv(64, (5,5), 1, padding = "same")(conv_g3)# RF - 22
max_g1 = AveragePooling2D((2,2),strides=(1,1), padding="same")(E_merge)
conv_g5 = Conv2D(64, (1,1))(max_g1)
conv_9 = Conv2D(64,(1,1))(E_merge) #RF - 18
#merge_1 = merge([conv_g2, conv_g4, conv_g5, conv_9], mode = "concat",
concat_axis =-1)# RF - 18, 22, 20, 36
merge_1 = Concatenate(axis=-1)([conv_g2, conv_g4, conv_g5, conv_9])
conv_g6 = bn_conv(32, (1,1), 1, padding = "same")(merge_1)
conv_g7 = bn_conv(64, (3,3), 1, padding = "same", dilation_rate = (1,1))
(conv_g6)
conv_g8 = bn_conv(32, (1,1), 1, padding = "same")(merge_1)
conv_g9 = bn_conv(128, (3,3),1, padding = "same", dilation_rate =(2,2))
(conv_g8)
#max_g2 = MaxpPooling2D(2,2, border_mode="same")(merge_1)
conv_g10 = Conv2D(64, (1,1), padding ="same")(merge_1)
#merge_2 = merge([conv_g7, conv_g9, conv_g10], mode = "concat",
concat_axis =-1)
merge_2 = Concatenate(axis=-1)([conv_g7, conv_g9, conv_g10])
#conv_9 = bn_conv(64, (3,3), 1, border_mode = "valid")(merge_2)
#conv_10 = bn_conv(128, (3,3), 1, border_mode = "valid")(conv_9)
conv_11 = Conv2D(32, (1,1))(merge_2)
conv_12 = Conv2D(10,(16,16))(conv_11)
flat = Flatten() (conv_12)
act = Activation("softmax")(flat)
model = Model(inputs=input, outputs=act)
return model
model = my_model([3, 32, 32], 10)
Для Конкатенации получается следующая ошибка
AttributeError Traceback (most recent call last)
<ipython-input-63-6acaac7e556d> in <module>()
97 return model
98
---> 99 model = my_model([3, 32, 32], 10)
100 from keras.optimizers import Adam
101
24 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)
1323 ValueError: if a cycle is detected.
1324 """
-> 1325 node = layer._inbound_nodes[node_index]
1326
1327 # Prevent cycles.
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'