My first unsupervised, supervised deep learning project - Part II
Introduction
The second part of this project is a product similarity model using product images. The idea is to input an image and have the model output the most similar products based on features that the pretrained VGG16 model was able to detect in that image and filtered on attributes detected in part 1 of the project. A combination of images and text has proven to yield a higher accuracy and gives the data scientist more control over the model.
The image above is an example, where the red pump is the test image and the bottom 6 pumps are the most similar items in my dataset.
Things to remember:
- Filters allow you to play with recommendations. The more filters you add, the more accurate the recommendation. You can also use filters to recommend items in different categories i.e. a sandal with a similar style as a pump.
- Recommendations are only as good as the dataset.
Methodology
Feature Extraction
I used the features that the VGG16 model was able to detect to determine the similarity of two images. The VGG16 model is able to detect many patterns and textures that can help define an image. I created a feature vector for each image, which consists of the output of the last dense layer (before the layer that classifies the images), which is basically the output of each activation function of each node in that layer.
PCA
I reduce dimensionality from 4096 features to 300 features using Principle Component Analysis (PCA), which is a dimensionality reduction technique (see curse of dimensionality) that creates "principal components", which are linear transformations of the 4096 features. These principal components are ordered in such a way that the first one explains the most variance.
Similarity Measure
To find the similarity between feature vectors, I needed a way to calculate how far or close they are from each other. I chose to use a simple euclidean distance, which worked well.
The first image displayed has a feature vector with the smallest distance from the feature vector of my test image. Similarity is another way to think about the problem and in this case, basically the opposite of distance. To determine how similar an image is, I transformed my distances using a min-max normalization technique and subtracted the value from 1.
What this basically does is normalize my similarity values and puts them on a scale of 0 to 1, where 0 is the most dissimilar and 1 is the most similar.
Demo
The model shows the most visually similar images, filtered on two detected attributes: the department and the athletics binary feature. I'm very happy with the outcome and performance of this model. Enjoy the demo!
This is a very high level explanation of what I have done. For more information please don't hesitate to contact me - always happy to share the love!