我试图连接模型中的各层,但出现错误,我在StackOverflow上检查了错误的解决方案,但无法在我的代码中实现。
我尝试实现['FmriPictures','FmriVernike','FmriWgWords','RestingState']
和tf.concat()
,但是对他们来说,我也遇到类似keras.layers.Concatenate
对象没有属性NoneType
的错误。
_inbound_nodes
对于Concatenate出现以下错误
# 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)
答案 0 :(得分:0)
merge
模块在一段时间前已从keras中删除,您有两个选择:
连接功能API:
from keras.layers import concatenate
E_merge = concatenate([skip1, skip2, conv_8], axis=-1)
连接层:
from keras.layers import Concatenate
E_merge = Concatenate(axis=-1)([skip1, skip2, conv_8])