Tensorflow Similarity Model (Part 2) — Finding similar items on Fashion MNIST

Finding nearest items on Fashion MNIST
High-level overview of the project implementation
  • Dataset preparation
  • Model training
  • Model evaluation (offline)
  • Building an interactive web-app for running product recommendation system

Step 1: Dataset preparation

  • Download data to a local directory
  • Reshape train and test data into proper shape required for model training step
  • Select a subset of test images (in tensor format) and convert and save the images to a local directory (required for web app)

Step 2: Model training

x_train = np.load(os.path.join(data_dir, "train_images.npy"))    y_train = np.load(os.path.join(data_dir, "train_labels.npy"))    num_classes = len(np.unique(y_train))# data sampler that generates balanced batches from fashion-mnist datasetsampler = MultiShotMemorySampler(
x_train,
y_train,
classes_per_batch=num_classes, # make sure all classes are available in each batch
)
# build model architecture
inputs = layers.Input(shape=(28, 28, 1))
x = layers.Rescaling(1 / 255)(inputs)
x = layers.Conv2D(64, 3, activation="relu")(x)
x = layers.Flatten()(x)
x = layers.Dense(64, activation="relu")(x)
outputs = MetricEmbedding(64)(x)
model = SimilarityModel(inputs, outputs)
model.index(x=x_train, y=y_train, data=x_train)

Step 3: Model evaluation (optional)

Step 4: Building an interactive web app

Selected Pullover
Nearest Pullovers found

My key takeaway

--

--

--

Knowledge is power, but shared knowledge is far more powerful

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Classification Metrics & Thresholds Explained

Predicting the publisher’s name from an article: A case study

Face recognition using Transfer learning

The Youtube Algorithm: How Does it Work?

Gated Multimodal Units for Information Fusion

Linear Algebra 101 — Part 3

Weight Initialization Technique in Neural Networks

Foundations of NLP Explained Visually: Beam Search, How it Works

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ata-tech

Ata-tech

Knowledge is power, but shared knowledge is far more powerful

More from Medium

Deploy BERT Chinese text classification model on Triton

Making Sense of Positional Encoding in Transformer Architectures with Illustrations

CoreDump: A Dump on BERT for UOL 662

Part of Speech (POS) Tagging in NLP