Несоответствие формы в сиамской модели Keras - PullRequest
0 голосов
/ 05 июня 2018

Я пытаюсь реализовать сиамскую модель на наборе данных mnist с функцией потери триплета и испытываю трудности с управлением фигурами, возможно, в конечном лямбда-слое модели.Это то, что я сделал до сих пор ...

#Dataset
pairs_train.shape #(54200, 3, 28, 28)->each sample contain 3 images(anchor,positive,negative)
pairs_test.shape #(8910, 3, 28, 28)

#Base model
input_shape = (28,28)
input = Input(shape = input_shape)
x = Flatten()(input)
x = Dense(128 , activation = "relu")(x)
x = Dropout(0.1)(x)
x = Dense(128 , activation = "relu")(x)
x = Dropout(0.1)(x)
x = Dense(128 , activation = "relu")(x)

#Sharing
base_network = Model(input , x)
input_1 = Input(shape = input_shape)
input_2 = Input(shape = input_shape)
input_3 = Input(shape = input_shape)

output_1 = base_network(input_1)
output_2 = base_network(input_2)
output_3 = base_network(input_3)

#Function to stack final outputs for calculating triplet loss
def func(x):
    return K.stack([x[0] , x[1] , x[2]] , axis = -1)

#Final lamda layer -> This is where problem lies I think.
finalOutput = Lambda(func)([output_1 , output_2 , output_3])

#Final model
finalModel = Model(inputs=[input_1 , input_2 , input_3] , outputs = finalOutput)

finalModel.compile(loss = triplet_loss , optimizer=RMSprop() , metrics = ["accuracy"])
y_dummie = np.ones(54200)
finalModel.fit([pairs_train[:,0] , pairs_train[:,1] , pairs_train[:,2]] , np.ones(54200),
         batch_size = 128 , epochs = 200)

во время обучения я получаю следующую ошибку.

Cannot feed value of shape (128, 1) for Tensor 'lambda_5_target:0', which has shape '(?, ?, ?)'

Пожалуйста, помогите ...

...