我尝试了解三重态损耗架构。我找到了一个简单的mnist数据库示例:https://github.com/KinWaiCheuk/Triplet-net-keras/blob/master/Triplet%20NN%20Test%20on%20MNIST.ipynb
但是我不明白它是如何工作的。
有
def create_base_network(in_dims):
"""
Base network to be shared.
"""
model = Sequential()
model.add(Conv2D(128,(7,7),padding='same',input_shape=(in_dims[0],in_dims[1],in_dims[2],),activation='relu',name='conv1'))
model.add(MaxPooling2D((2,2),(2,2),padding='same',name='pool1'))
model.add(Conv2D(256,(5,5),padding='same',activation='relu',name='conv2'))
model.add(MaxPooling2D((2,2),(2,2),padding='same',name='pool2'))
model.add(Flatten(name='flatten'))
model.add(Dense(4,name='embeddings'))
return model
作者制作模型:
anchor_input = Input((28,28,1, ), name='anchor_input')
positive_input = Input((28,28,1, ), name='positive_input')
negative_input = Input((28,28,1, ), name='negative_input')
# Shared embedding layer for positive and negative items
Shared_DNN = create_base_network([28,28,1,])
encoded_anchor = Shared_DNN(anchor_input)
encoded_positive = Shared_DNN(positive_input)
encoded_negative = Shared_DNN(negative_input)
merged_vector = concatenate([encoded_anchor, encoded_positive, encoded_negative], axis=-1, name='merged_layer')
model = Model(inputs=[anchor_input,positive_input, negative_input], outputs=merged_vector)
model.compile(loss=triplet_loss, optimizer=adam_optim)
因此,结果如下:
图显示了sequence_7具有输入形式(None,28、28、1),并且不接受一个输入,而是接受三个输入(锚定,正负)。怎么可能?
谁能解释一下,数据如何通过此图传递?