连体网络
我正在尝试实现连体神经网络,并运行此代码
def build_network(conv_model):
input_shape = (105, 105, 1)
input1 = Input(input_shape)
input2 = Input(input_shape)
model = conv_model(input_shape)
model_output_left = model(input1)
model_output_right = model(input2)
def l1_distance(x):
return K.abs(x[0] - x[1])
def l1_distance_shape(x):
print(x)
return x[0]
# merged_model = Merge([model1, model2], mode=l1_distance, output_shape=lambda x: x[0])
merged_model = merge([model_output_left, model_output_right], mode=l1_distance, output_shape=l1_distance_shape)
output = Dense(1, activation='sigmoid')(merged_model)
siamese_model = Model([input1, input2], output)
return siamese_model
然后我跑去制作模型
siamese_model1 = build_network(conv_model)
siamese_model1.compile(loss='binary_crossentropy', optimizer=Adam(0.00006), metrics=['acc'])
siamese_model1.summary()
然后我得到错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-28-7405baecdb7f> in <module>()
----> 1 siamese_model1 = build_network(conv_model)
2 siamese_model1.compile(loss='binary_crossentropy', optimizer=Adam(0.00006), metrics=['acc'])
3 siamese_model1.summary()
<ipython-input-27-294ae7b24fbc> in build_network(conv_model)
20
21 # merged_model = Merge([model1, model2], mode=l1_distance, output_shape=lambda x: x[0])
---> 22 merged_model = merge([model_output_left, model_output_right], mode=l1_distance, output_shape=l1_distance_shape)
23 output = Dense(1, activation='sigmoid')(merged_model)
24 siamese_model = Model([input1, input2], output)
TypeError: 'module' object is not callable
我有人帮我解决这个问题吗?或评论如何解决?