Image Recommendations with PyTorch + Flask + PostgreSQL + Heroku deployment

Image Recommendations with PyTorch + Flask + PostgreSQL + Heroku deployment

Packaging a PostgreSQL/ PyTorch based image recommender system with Flask, importing data and running it on the Heroku cloud application platform.

Packaging a PostgreSQL/ PyTorch based image recommender system with Flask, importing data and running it on the Heroku cloud application platform.

During the last weeks I have implemented an item-to-item image recommender system that uses PyTorch’s pretrained Resnet18 convolutional neural network to generate comparability through feature vectors, a database to manage the images and top-k lists and a user interface.

The developed solution and steps for the deployment on Heroku are presented in this article and the code is available on GitHub.

I have set and solved the following _requirements _for this project

1. The web app is accessible on the internet.

2. The application has a gallery of images with pagination, loading only the relevant data for the page.

3. The data for the gallery and the recommendations is fetched from a database.

4. The recommendations are most similar images from a possibly large image set. They must appear instantaneously; this means that the similarity calculation happens offline.

5. The gallery is responsive.

6. The Flask application is suitable packaged for future extensions/reuse.

In my last post already parts of the requirements were realized as prototype, in particular 2 and 4. A Jupyter notebook is available at GitHub for the Resnet18 PyTorch recommender that takes an image as input and gives out most similar images from the same image set. To use the Flask app this notebook should be used to generate Pandas dataframes that are stored as pickle files. These are used as static content in the app.

In this post we will show how to realize also all other requirements, how to use an SQLite database locally and PostgreSQL on Heroku, how to use it for pagination, how to clean-up the work and to deploy it to Heroku make it available on the internet via browser on PCs or smartphones.

You can access and test the demo app with a few images on Heroku through the following link:

Logo mds

This post is structured in the following sections:

1. The features of the app are described

2. It is revisited how to calculate the similarities between images

3. The packaging structure for the application is described

4. The SQL model is presented

5. The backend application logic is introduced

6. The templates are introduced

7. All steps for the Heroku deployment are explained

8. A conclusion is made

Note, for this article I was using a Windows 10 machine and Python 3.5.4. I have left out any exception handling.

recommender-systems heroku postgres python machine-learning

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Machine Learning Developers in India

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

Applications of machine learning in different industry domains

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

Hire Machine Learning Developer | Hire ML Experts in India

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

How To Plot A Decision Boundary For Machine Learning Algorithms in Python

How To Plot A Decision Boundary For Machine Learning Algorithms in Python, you will discover how to plot a decision surface for a classification machine learning algorithm.

How To Get Started With Machine Learning With The Right Mindset

You got intrigued by the machine learning world and wanted to get started as soon as possible, read all the articles, watched all the videos, but still isn’t sure about where to start, welcome to the club.