Deploy Keras Neural Network to Flask web service | Part 1 - Overview
text
Intro to Keras Neural Network Deployment with Flask
Over the next several episodes, we'll be working to deploy a Keras model to a Flask web service.
In this episode, we're going to discuss what this means and why we'd want to do this. We'll also get a glimpse of what the final product will look like. Let's get to it!
What does it mean to deploy a model?
We're going to be working to deploy a Keras model to a web service... But what exactly does this mean? Deploying to a web service? Why would we do it anyway?
Well, so far in this series, anytime we've built a model, trained a model, or used a model for inference, it's been within a Jupyter notebook, right? That's totally fine... For testing and developing purposes.
What about after we have a satisfactory model though, and we want to use it or access it from an app?
Well, we're not going to be using Jupyter notebook to do that. We can't access a model in a Jupyter notebook from an outside app. What if our app isn't even written in Python? What will we use in that case?
One very viable option is to use a web service. This means apps that we build that need to use our models, regardless of which language they're written in, will be able to access the models over the web using HTTP.
So, we'll be moving a Keras model to a web service, i.e. deploying it to a web service, and once that's done, we'll be able to access and utilize our model over HTTP from other apps, and we'll even see how we can interact with our model from the browser.
The model we'll use is the fine-tuned VGG16 model that we worked with earlier in this series to predict on images of cats and dogs, but the steps we go through together for this can be used for whatever model you choose to work with.
Project overview
Our end goal will be to deploy the trained model to a Flask web service. Then from the browser, we'll send an image of a cat or dog to the web service, and have it respond with the model's predictions.
Curious how that might look? Let's check it out.
This is a very simple, no frills web app I created. From this page, we can choose an image of a cat or dog, press the predict button, and get predictions. See the corresponding video for the full demo.
What's actually happening is that this web app, written in HTML and Javascript, is making an HTTP call to a Flask web service, which is written in Python. By making an HTTP call, I mean that we're calling on the web service to do something for us. We also refer to this as an HTTP request.
Now, this web service is hosting our VGG16 model, and when we call it, we're requesting for it to send us back a prediction from our model for the given image that we send it. Once we receive that response, we display it on our web page.
This is what we're going to be building together. We'll develop the front end, which we'll refer to as the web app, and we'll also develop the backend, which will be the Flask web service.
As mentioned earlier, the backend will be written in Python, which you should already be comfortable with since you're working with Keras. The frontend will be written in HTML and Javascript. If you're not already familiar with these, it won't be a problem.
Generally, you can think of HTML as the language that provides the structure of the webpage, and Javascript as the language that all the logic is written in. We'll be going step by step in the code stating the intention for each line, so don't worry.
Something that's cool is, even though the app we're building to call the backend web service will be a web app, the web service will be able to be called by any app using an HTTP request, regardless of what language the app is in.
We'll kick off our next episode by getting ourselves familiar with Flask and installing it. Until then, let me know in the comments if you'll be following along with this project. See ya there!
quiz
resources
updates
Committed by on