Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions examples/mnist_siamese_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ def compute_accuracy(predictions, labels):
'''Compute classification accuracy with a fixed threshold on distances.
'''
preds = predictions.ravel() < 0.5
return ((preds & labels).sum() +
(np.logical_not(preds) & np.logical_not(labels)).sum()) / float(labels.size)
return np.mean(preds == labels)


def accuracy(y_true, y_pred):
'''Compute classification accuracy with a fixed threshold on distances.
'''
return K.mean(K.equal(y_true, K.cast(y_pred < 0.5, y_true.dtype)))


# the data, shuffled and split between train and test sets
Expand Down Expand Up @@ -117,7 +122,7 @@ def compute_accuracy(predictions, labels):

# train
rms = RMSprop()
model.compile(loss=contrastive_loss, optimizer=rms)
model.compile(loss=contrastive_loss, optimizer=rms, metrics=[accuracy])
model.fit([tr_pairs[:, 0], tr_pairs[:, 1]], tr_y,
batch_size=128,
epochs=epochs,
Expand Down