December 2019
Intermediate to advanced
468 pages
14h 28m
English
In this section, we'll use Keras to implement a simple example of Siamese networks, which will verify whether two MNIST images are from the same class or not. It is partially based on https://github.com/keras-team/keras/blob/master/examples/mnist_siamese.py.
Let's look at how to do this step by step:
import randomimport numpy as npimport tensorflow as tf
def create_pairs(inputs: np.ndarray, labels: np.ndarray): num_classes = 10 digit_indices = [np.where(labels == i)[0] for i in range(num_classes)] pairs = list() labels = list() n = min([len(digit_indices[d]) ...
Read now
Unlock full access