5.0 / 5
We will cover the following tasks in 1 hour and 1 minute:
We will understand the Rhyme interface and our learning environment. You will get a virtual machine, you will need Jupyter Notebook and TensorFlow for this course and both of these are already installed on your virtual machine. Jupyter Notebooks are very popular with Data Science and Machine Learning Engineers as one can write code in cells and use other cells for documentation.
The machine is already setup with everything we will need for this course. As a starting point, we can use our virtual environment which has the packages already installed. Type
venv\scripts\activate and this will launch the virtual environment. Now, if you type
flask run, the app will launch. Now we can try out the app. We will test it out with a few images.
We are trying to create a super simple hello world web app with Flask. This will have just one route for the home page which will display just a simple “hello world” message for now. In the next few chapters, we will iteratively keep working on this file.
Load the Model
In order to load our model, we will need to import Keras and TensorFlow. The way to load a pre-trained model is to first create an instance of a model with the exact same architecture as what you used when you trained the model. So, we trained this model in one of our previous courses on computer vision. The course was called transfer learning and our model was trained on a glass vs table data. The ResNet50 model trained on ImageNet is pretty big so it will take some time to load so just be patient.
In the previous chapter, we creted a model and loaded weights from an earlier training. This means that our model is now ready to make predictions. Except the problem is that we need to pre-process incoming images before we can actually get the model to make predictions on them. This is because the model expects tensors of certain shape so we need to convert our incoming images accordingly. We will need a couple of methods from the image preprocessing library of Keras. Let’s define a method called
prepare_images which will return processed data suitable for our model given a list of images
We will write a method which will return a string based on our model’s prediction given an image. Our model was trained on the Glass vs Table dataset and predicts whether an image is of a glass or a table. We will be sure to use TensorFlow’s default graph.
Let Users Upload Images
In this chapter, we will finally finish writing our
show_main method which will render a bit of html to let users upload images. Then, we will use the
make_prediction method written in the previous chapter to make a prediction an uploaded image. Once everything is working, we will go to Chrome and go to the localhost. There, we have the upload form. We will upload an image from our tests folder and take a look at the prediction.
Very useful course
About the Host (Amit Yadav)
I am a machine learning engineer with focus in computer vision and sequence modelling for automated signal processing using deep learning techniques. My previous experiences include leading chatbot development for a large corporation.