Siamese networks – the MNIST dataset

In this tutorial, we will do the following things in the order listed here:

  1. Data preprocessing: Creating pairs
  2. Creating a Siamese network architecture
  3. Training it using the small MNIST dataset
  4. Visualizing the embeddings

Perform the following steps to carry out the exercise:

  1. First, import all the libraries needed using the following code:
# -*- encoding: utf-8 -*-import argparseimport torchimport torchvision.datasets as dsetsimport randomimport numpy as npimport timeimport matplotlib.pyplot as pltfrom torch.autograd import Variablefrom torchvision import transformsimport pickleimport torchimport torch.nn as nn

As we learned in the theoretical Understanding Siamese networks section, as part of data preprocessing, ...

Get Hands-On One-shot Learning with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.