Git Product home page Git Product logo

azure-webapp-w-cntk's Introduction

Deploy CNTK to Azure Web Apps

Azure offers several ways of deploying a deep-learning model (e.g. CNTK): Windows Web App, Linux (Docker) Web App, and Azure Container Services (Docker). Both of the Docker methods are perhaps more convenient, however they are not publicly available at the time of writing. Hence, in this post we will deploy a ResNet-18 model to Azure Web Apps and then submit some test pictures to it using a sample HTML interface and also via python.

Result:

Website Demo

HTML

Demo

Python

Demo

The above screenshot is taken from this notebook. If you wish to run some speed-tests then this notebook shows how to submit asyncrochonous requests to the created API to get an idea of how long it takes to classify images in bulk.

Replicate Demo

  1. Download the contents of this repo and open a Command Prompt in the folder

  2. Run the following commands to check you have git and azure-cli installed:

    az --version  # time-of-writing: 2.0.1
    pip install azure-cli  # otherwise install azure-cli
    git --version # time of writing: 2.9.2.windows.1
    
  3. Set your username and password for local git deployment (you only need to do this once) e.g.:

    set uname=<username_for_local_git_deployment>
    set pass=<password_for_local_git_deployment>
    # Create a user-name and password for git deployment of all your apps
    az appservice web deployment user set --user-name %uname% --password %pass%
    
  4. Create your web-app by running the below commands:

    # Name for your web-app
    set appn=<app_name>
    # Name for resource-group containing web-app
    set rgname=<name_for_resource_group_that_contains_app>
    # Login to azure
    az login
    # Create a resource-group
    az group create --location westeurope --name %rgname%
    # Create a paid 'S2' plan to support your app
    # The standard paid plans are: S1, S2, S3
    az appservice plan create --name %appn% --resource-group %rgname% --sku S2
    # Create the web-app
    az appservice web create --name %appn% --resource-group %rgname% --plan %appn%
    # Configure for local git deployment (SAVE URL)
    az appservice web source-control config-local-git --name %appn% --resource-group %rgname% --query url --output tsv
    # Initialise your git repo
    git init
    # Add the azure endpoint
    git remote add azure <PASTE_URL_FROM_ABOVE>
    # e.g. git remote add azure https://[email protected]/wincntkdemo.git
    
  5. We will now install Python. Navigate to your web-app on Azure Portal, scroll down to the "Extensions" blade and select it:

    Demo

    Then, click on "Add", locate "Python 3.5.3 x64" and add it (you must use this extension)

    Demo

    Make sure you get a notification that this installed successfully:

    Demo

  6. (Optional) Under the "Application settings" blade set "Always On" to "On" to reduce the response time (since your model will be kept loaded)

  7. Deploy this demo by running:

    git add -A
    git commit -m "init"
    git push azure master
    

    If everything has gone successfully you should see the following line in the script output:

    remote: Successfully installed cntk-2.0rc1
    remote: ..
    remote: 2.0rc1
    

You should now be able to navigate to your web-app address and upload a photo that will be classified according to the CNN: ResNet-18

Advanced modifications (run your own)

  1. You can include references to other modules (e.g. pandas or opencv) in your model.py file, however you must add the module to the "requirements.txt" file so that python installs the module. If the module needs to be built you can you can go to http://www.lfd.uci.edu/~gohlke/pythonlibs/ to download the pre-built wheel file (to the wheels folder). Don't forget to add the wheel path to the "requirements.txt" file at the root of the directory. Note: Numpy, Scipy, and CNTK wheels are automatically installed inside the "deploy.cmd" script; to change this you can edit the deploy.cmd file to point to whichever numpy wheel you require

  2. Editing deploy.cmd - the install script automatically adds the binaries for CNTK v2.0 rc1. However if you want to use Python 3.6 or CNTK v2.0 rc1+ then alter the below in the "deploy.cmd" script:

    :: VARIABLES
    echo "ATTENTION"
    echo "USER MUST CHECK/SET THESE VARIABLES:"
    SET PYTHON_EXE=%SYSTEMDRIVE%\home\python353x64\python.exe
    SET NUMPY_WHEEL=https://azurewebappcntk.blob.core.windows.net/wheels/numpy-1.12.1+mkl-cp35-cp35m-win_amd64.whl
    SET SCIPY_WHEEL=https://azurewebappcntk.blob.core.windows.net/wheels/scipy-0.19.0-cp35-cp35m-win_amd64.whl
    SET CNTK_WHEEL=https://azurewebappcntk.blob.core.windows.net/cntkrc/cntk-2.0rc1-cp35-cp35m-win_amd64.whl
    SET CNTK_BIN=https://azurewebappcntk.blob.core.windows.net/cntkrc/cntk.zip
    

    To create the 'cntk.zip' file you just need to extract the cntk/cntk folder (i.e. the folder that contains 'CNTK.exe' and DLLs; you can remove the python sub-folder which contains the wheels, if it exists) and then reference it with the %CTNK_BIN% environmental variable above.

  3. You can also install a different python extension if you wish, however make sure to reference it properly (and also to get the Numpy, Scipy and CNTK Wheels for it). For example, the "Python 3.5.3 x64" extension is installed in the directory "D:\home\python353x64", and thus the script references: SET PYTHON_EXE=%SYSTEMDRIVE%\home\python353x64\python.exe

  4. Finally, alter the "model.py" script as desired in the folder "WebApp", along with the HTMl template, "index.html" in "templates" and then push your changes to the repo:

    git add -A
    git commit -m "modified some script"
    git push azure master
    

azure-webapp-w-cntk's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

azure-webapp-w-cntk's Issues

Webdeployment Failed

Hi
I am new to this and when I give the command git push azure master I get following error

C:\Users\bhagyashreep\Azure-WebApp-w-CNTK-master\Azure-WebApp-w-CNTK-master>git push azure master
Counting objects: 29, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (29/29), 60.30 MiB | 613.00 KiB/s, done.
Total 29 (delta 2), reused 0 (delta 0)
remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id '3d8949e152'.
remote: Running custom deployment command...
remote: Running deployment command...
remote: "ATTENTION"
remote: "USER MUST CHECK/SET THESE VARIABLES:"
remote: "Installed python extension installed here:"
remote: D:\home\python353x64\python.exe
remote: "Numpy wheel and version located here:"
remote: https://azurewebappcntk.blob.core.windows.net/wheels/numpy-1.12.1+mkl-cp35-cp35m-win_amd64.whl
remote: "Scipy wheel and version located here:"
remote: https://azurewebappcntk.blob.core.windows.net/wheels/scipy-0.19.0-cp35-cp35m-win_amd64.whl
remote: "CNTK Wheel and version located here:"
remote: https://azurewebappcntk.blob.core.windows.net/cntkrc/cntk-2.0rc1-cp35-cp35m-win_amd64.whl
remote: "CNTK Binaries and version located here:"
remote: https://azurewebappcntk.blob.core.windows.net/cntkrc/cntk.zip
remote: Handling python deployment.
remote: KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
remote: Deleting file: 'hostingstart.html'
remote: Copying file: '.gitignore'
remote: Copying file: 'README.md'
remote: Copying file: 'requirements.txt'
remote: Copying file: 'logs_init_.txt'
remote: Copying file: 'Model\ResNet_18.model'
remote: Copying file: 'Model\synset-1k.txt'
remote: Copying file: 'readme_support\extensions_1.JPG'
remote: Copying file: 'readme_support\extensions_2.JPG'
remote: Copying file: 'readme_support\python_result.JPG'
remote: The system cannot find the path specified.
remote: Copying file: 'readme_support\requirement.JPG'
remote: Copying file: 'readme_support\REST.ipynb'
remote: Copying file: 'readme_support\REST_Speed_Test.ipynb'
remote: Copying file: 'readme_support\result.JPG'
remote: Copying file: 'readme_support\test.jpg'
remote: Copying file: 'WebApp\model.py'
remote: Copying file: 'WebApp\runserver.py'
remote: Copying file: 'WebApp\templates\index.html'
remote: Copying file: 'Wheels\Pillow-4.0.0-cp35-cp35m-win_amd64.whl'
remote: Copying file: 'web.config'
remote: Detected requirements.txt. You can skip Python specific steps with a .skipPythonDeployment file.
remote: "Configuring pip"
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
To https://bpwebapp1.scm.azurewebsites.net/bpwebapp1.git

  • [new branch] master -> master

any help as to why this is failing

load_model() in cntk problem

Hi,

I am using cntk2.2 and FasterRcnn algo to train my data set. train and evaluate works fine on my machine and I get results. But when I try to load the model in Azure web app using the load_model() function I get ERROR 500 saying internal error. Any pointers as to why this my happen.

Deploying Fast R-CNN model as Azure WebApp

I have developed a Fast R-CNN model using this tutorial. I want to deploy the model obtained. I already have a resource group created. I don't want to create another resource group. So the order in which I run the commands is as follows.

  1. set uname=<username_for_local_git_deployment>
  2. set pass=<password_for_local_git_deployment>
  3. az webapp deployment user set --user-name %uname% --password %pass%
    (I am using 'webapp' instead of 'appservice web')
  4. set appn=<app_name> (same as present in the portal)
  5. set rgname=<name_for_resource_group_that_contains_app>
  6. az login
    (I am not running the steps in between since I don't have to create a resource group and an app service, becuase they are already created manually from Azure Portal)
  7. az appservice web source-control config-local-git --name %appn% --resource-group %rgname% --query url --output tsv (after running this I get an error saying that, 'all appservice web commands have been renamed to webapp'). So when I change appservice web to webapp and try running the same command I get an error saying 'az webapp: error: argument subcommand: invalid choice: source-control'

I don't face any login issues. I don't understand what am I supposed to do. Can you explain the solution to deploy any model developed from Fast R-CNN tutorial. Am I following the right tutorial to deploy Fast R-CNN model? Is there any other way I can do it, if not this way?

Remote hungs up unexpectaedly while pushing to azure master

Following your step by step instruction, I have,

  1. Cloned your repo
  2. Created an web app using azure portal with web browser
  3. Scaled up service plan to S1
  4. Added python 3.5.3 x64
  5. Set 'Always On' to On
  6. Tried to push to azure master using git bash.
    And then the following message had been displayed:

$ git push azure master Counting objects: 25, done. Delta compression using up to 4 threads. Compressing objects: 100% (19/19), done. error: RPC failed; curl 56 SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054 fatal: The remoteWriting object end hung up unexpectedly Writing objects: 100% (25/25), 59.78 MiB | 6.00 KiB/s, done. Total 25 (delta 0), reused 0 (delta 0) fatal: The remote end hung up unexpectedly Everything up-to-date

From Log-Stream of azure portal I got the following:
`Connecting...
2017-04-08T12:02:48 Welcome, you are now connected to log-streaming service.
2017-04-08 12:02:36 CNTKWEBAPPFRRAHAT GET / X-ARR-LOG-ID=edcf5ee8-1a92-4787-b4ec-4ec57ef13be1 80 - 13.85.72.129 AlwaysOn ARRAffinity=f48a766e7a568de51e4d0599762c3f8516fe1cb9a63fdeab6282af05db2ec8ed - cntkwebappfrrahat.azurewebsites.net 200 0 0 67469 670 126
2017-04-08 12:02:44 ~1CNTKWEBAPPFRRAHAT GET / - 80 - 100.114.220.57 AlwaysOn - - cntkwebappfrrahat.azurewebsites.net 200 0 0 2943 473 8931
2017-04-08 12:02:46 CNTKWEBAPPFRRAHAT GET / X-ARR-LOG-ID=525f409c-bb3e-471a-9d0b-293f7b535e1f 80 - 13.85.72.129 AlwaysOn ARRAffinity=f48a766e7a568de51e4d0599762c3f8516fe1cb9a63fdeab6282af05db2ec8ed - cntkwebappfrrahat.azurewebsites.net 200 0 0 67469 670 20
2017-04-08 12:02:46 ~1CNTKWEBAPPFRRAHAT GET / - 80 - 100.114.220.57 AlwaysOn - - cntkwebappfrrahat.azurewebsites.net 200 0 0 2943 473 36
2017-04-08 12:02:46 ~1CNTKWEBAPPFRRAHAT GET /cntkwebappfrrahat.git/info/refs service=git-receive-pack&X-ARR-LOG-ID=cbbedd3f-95dc-47ca-91b7-f0bb1e6c8bbd 443 - 103.58.74.138 git/2.12.0.windows.1 - - cntkwebappfrrahat.scm.azurewebsites.net 200 0 0 763 1021 1418
2017-04-08 12:02:53 ~1CNTKWEBAPPFRRAHAT POST /cntkwebappfrrahat.git/git-receive-pack X-ARR-LOG-ID=b6e4a0c4-0cdf-4054-9a9f-5c892c5747af 443 - 103.58.74.138 git/2.12.0.windows.1 - - cntkwebappfrrahat.scm.azurewebsites.net 200 0 0 507 1705 2211
2017-04-08T12:04:48 No new trace in the past 1 min(s).
2017-04-08T12:05:05 Outgoing response, type: response, statusCode: 500, statusText: Internal Server Error, Server: Microsoft-IIS/8.0

<title>IIS Detailed Error - 500.0 - Internal Server Error</title> <style type="text/css"> </style>

HTTP Error 500.0 - Internal Server Error

Internal Server Error

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:

  • Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
  • Check the event logs to see if any additional information was logged.
  • Verify the permissions for the DLL.
  • Install the .NET Extensibility feature if the request is mapped to a managed handler.
  • Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:

Module   ManagedPipelineHandler
Notification   ExecuteRequestHandler
Handler   Kudu.Services.GitServer.ReceivePackHandler
Error Code   0x800703e3
Requested URL   https://~1cntkwebappfrrahat:80/cntkwebappfrrahat.git/git-receive-pack
Physical Path   D:\Program Files (x86)\SiteExtensions\Kudu\61.60316.2745\cntkwebappfrrahat.git\git-receive-pack
Logon Method   Anonymous
Logon User   Anonymous

More Information:

This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

View more information »

Microsoft Knowledge Base Articles:

2017-04-08T12:05:50 Outgoing response, type: response, statusCode: 500, statusText: Internal Server Error, Server: Microsoft-IIS/8.0 <title>IIS Detailed Error - 500.0 - Internal Server Error</title> <style type="text/css"> </style>

HTTP Error 500.0 - Internal Server Error

Internal Server Error

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:

  • Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
  • Check the event logs to see if any additional information was logged.
  • Verify the permissions for the DLL.
  • Install the .NET Extensibility feature if the request is mapped to a managed handler.
  • Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:

Module   ManagedPipelineHandler
Notification   ExecuteRequestHandler
Handler   Kudu.Services.GitServer.ReceivePackHandler
Error Code   0x800703e3
Requested URL   https://~1cntkwebappfrrahat:80/cntkwebappfrrahat.git/git-receive-pack
Physical Path   D:\Program Files (x86)\SiteExtensions\Kudu\61.60316.2745\cntkwebappfrrahat.git\git-receive-pack
Logon Method   Anonymous
Logon User   Anonymous

More Information:

This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

View more information »

Microsoft Knowledge Base Articles:

2017-04-08T12:07:48 No new trace in the past 1 min(s). 2017-04-08 12:07:49 ~1CNTKWEBAPPFRRAHAT GET / - 80 - 100.114.220.57 AlwaysOn - - cntkwebappfrrahat.azurewebsites.net 200 0 0 2946 473 5 2017-04-08 12:07:49 CNTKWEBAPPFRRAHAT GET / X-ARR-LOG-ID=e0513dc5-c4dd-41f5-b371-4569e19a87b4 80 - 13.85.72.129 AlwaysOn ARRAffinity=f48a766e7a568de51e4d0599762c3f8516fe1cb9a63fdeab6282af05db2ec8ed - cntkwebappfrrahat.azurewebsites.net 200 0 0 67469 670 8 2017-04-08T12:09:48 No new trace in the past 1 min(s). 2017-04-08T12:10:48 No new trace in the past 2 min(s). 2017-04-08T12:11:48 No new trace in the past 3 min(s). 2017-04-08T12:12:39 System.ApplicationException: The trace listener AzureBlobTraceListener is disabled. ---> System.InvalidOperationException: The SAS URL for the cloud storage account is not specified. Use the environment variable 'DIAGNOSTICS_AZUREBLOBCONTAINERSASURL' to define it. at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.RefreshConfig() --- End of inner exception stack trace ---

2017-04-08 12:12:50 ~1CNTKWEBAPPFRRAHAT GET / - 80 - 100.114.220.57 AlwaysOn - - cntkwebappfrrahat.azurewebsites.net 200 0 0 2946 473 15
2017-04-08 12:12:50 CNTKWEBAPPFRRAHAT GET / X-ARR-LOG-ID=812ade4d-e3c1-4974-974b-1aa9211aa704 80 - 13.85.72.129 AlwaysOn ARRAffinity=f48a766e7a568de51e4d0599762c3f8516fe1cb9a63fdeab6282af05db2ec8ed - cntkwebappfrrahat.azurewebsites.net 200 0 0 67469 670 15`

Did I miss anything?

CGI bad request error

Once I am done with deployment. I get CGI bad request error. Tried Kudu console debugging no issues there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.