Tutorial — Image Classifier using Resnet50 Deep Learning model (Python Flask in Azure)

Source: Deep Learning on Medium

Step 5 — Deploy the Flask App to Flask

To deploy the Flask App to Azure, let us create a Azure Web App with Linux as the OS.

Once the deployment is completed, the web app is available at — http://<app_name>.azurewebsites.net

Click the Deployment Centre and select the Local Git as the option for deployment:

In the next step select K App Service build service for deployment. Once you select Finish, a local Git repository url will be generated. The local Git repository would be off the form —
https://<azure app>.scm.azurewebsites.net:443/imageclassifier-flask.git.

Once you finish the Finish you would get a git repository url and also you have to set the user credentials under the FTP/Credentials in the Deployment Centre. Remember you would need the User Credentials while uploading the code from your git repository to Azure deployment Git repository.

Now go to the local git terminal. From your local git terminal add azure remote to your local git repository. First add the remote Url to the git repository you got from the deployment centre.

git remote add azure-dep https://<username>@<azure app>.scm.azurewebsites.net:443/imageclassifier-flask.git

Where <username> is the user name from the User Credentials that you have set in the Deployment Centre.
Where <aureApp> is the Azure Web Service App that you had provisioned for deploying this Flask App.

Now make any changes and commit your changes to the local git (git add . And git commit -m “My Changes”)

And you push your changes “azure-dep” to deploy with the following command:

git push azure-dep master

For the first time you would be prompted by credentials using the Git credentials manager. Make sure you that you enter the credentials you have configured in the Deployment Centre / User Credentials and not the credentials you use it for log into Azure portal.

After some time you will see following :

C:\TechSamples\GitRepos\imageclassifier>git push azure-dep master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 372 bytes | 372.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Deploy Async
remote: Updating branch ‘master’.
remote: Updating submodules.
remote: Preparing deployment for commit id ‘05dd65163d’.
remote: Oryx-Build: Running kudu sync…
remote: Kudu sync from: ‘/home/site/repository’ to: ‘/home/site/wwwroot’
remote: Ignoring: .deployment
remote: Copying file: ‘app.py’
remote: Deleting file: ‘app-backup.py’
remote: Ignoring: .git
remote: Running oryx build…
remote: Build orchestrated by Microsoft Oryx, https://github.com/Microsoft/Oryx
remote: You can report issues at https://github.com/Microsoft/Oryx/issues
remote:
remote: Oryx Version : 0.2.20190820.2, Commit: 450179ca187b5b9080175bb25f5b22466c63614b
remote: Build Operation ID: |o+ctvHS4LmU=.89e56537_
remote: Repository Commit : 05dd65163da9c9ac1e09533cbfb5201c9f6a83bc
remote: Source directory : /home/site/wwwroot
remote: Destination directory: /home/site/wwwroot
remote: Python Version: /opt/python/3.7.4/bin/python3
remote: Python Virtual Environment: antenv
remote: Creating virtual environment …
remote: Activating virtual environment …
remote: Upgrading pip…
remote: Requirement already up-to-date: pip in ./antenv/lib/python3.7/site-packages (19.2.3)
remote: Done in 7 sec(s).
remote: Running pip install…
remote: Done running pip install.
remote: Removing existing manifest file
remote: Creating a manifest file…
remote: Manifest file created.
remote: Done in 21 sec(s).
remote: Running post deployment command(s)…
remote: Deployment successful.
remote: App container will begin restart within 10 seconds.
remote: Deployment Logs : ‘https://imageclassifier-flask.scm.azurewebsites.net/newui/jsonviewer?view_url=/api/deployments/05dd65163da9c9ac1e09533cbfb5201c9f6a83bc/log’
To https://imageclassifier-flask.scm.azurewebsites.net:443/imageclassifier-flask.git
656a4c1..05dd651 master -> master

At this point your deployment is completed. You can check the status of deployment in the Deployment Center

You can browse to the deployed Azure Flask based application for Image classification here — https://imageclassifier-flask.azurewebsites.net/

This entire source code is available in the following Git hub repository. (https://github.com/venknar/imageclassifier)

In summary this sample demonstrates developing a simple ML App for image classification using Resnet 50 Deep Learning Model. It also takes you through on how to develop this app in Python Flask Framework and deploy the same to Azure Web Service.