我定义了一个典型的siamese网络架构,以获得我使用的编码temp_model(VGG模型,权重预训练有三重损失函数),在下面的代码中,最后我训练模型并作为h5文件保存到我的磁盘上,但是当我加载模型进行预测时,我得到了一个错误(ValueError:无效input_shape参数[(None,224, 224, 3), (None, 224, 224, 3), (None, 224, 224, 3)]: 模型有 1 个张量输入。
'''
left_input = Input(shape = (224, 224, 3))
right_input = Input(shape = (224, 224, 3))
# Generate the encodings (feature vectors) for the two images
encoded_l = temp_model([left_input,left_input,left_input])
encoded_r = temp_model([right_input,right_input,right_input])
# Add a customized layer to compute the absolute difference between the encodings
L1_layer = Lambda(lambda tensors:K.abs(tensors[0] - tensors[1]))
L1_distance = L1_layer([encoded_l, encoded_r])
L1_distance = Dense(512,activation='relu')(L1_distance)
L1_distance = Dropout(0.2)(L1_distance)
L1_distance = Dense(10,activation='relu')(L1_distance)
L1_distance = Dropout(0.2)(L1_distance)
# Add a dense layer with a sigmoid unit to generate the similarity score
prediction = Dense(1,activation='sigmoid')(L1_distance)
# Connect the inputs with the outputs
siamese_net = Model(inputs=[left_input,right_input],outputs=prediction)
siamese_net.compile(loss='binary_crossentropy', optimizer="adam",
metrics=['accuracy'])
siamese_net.summary()
# return the model
return siamese_net
“'” ---------------------------------------------------------------------------值错误回溯(最近一次调用最后一次)在 1 #final_model = siamese_model() ----> 2 final_model = load_model(“triplet_loss_function_vgg16_siamese_h100_128.h5”)
MMTTMM
冉冉说
相关分类