Closed ghost closed 6 years ago
Hi @bpatil16 ! First things first: this repository only shows how to use (already trained) model and expose it as a RESTful Python web service. It DOES NOT show how to train your own model. If you would like to train YOUR own model you may use my other repo. You should specifically check out Use with custom dataset part of documentation there.
To use this repo for YOU OWN model you should do the following steps:
CNTKModels
folder and change __C.CNTK.MODEL_NAME
variable in config.py to YOUR model nameCNTKModels
folder and change __C.CNTK.CLASS_MAP_FILE
variable in config.py to YOUR class map file name__C.CNTK.IMAGE_WIDTH = 1000
__C.CNTK.IMAGE_HEIGHT = 1000
__C.CNTK.NUM_CHANNELS = 3
app.py
script and verify it works correctly.
If you would like to deploy it to Azure Web Apps afterwards then just follow steps from README.MDSo answering your questions:
So I was following your github repo. I want to know what the purpose of .temp folder used by the webservice.
Temp folder is used by web service to temporary store images while evaluating them and plotting results.
I specifically want to know which folder are you storing the positive/negative and test images. generally its set up in the config.py file as __C.CNTK.MAP_FILE_PATH = parameter, its missing in the config.py file for this git repo.
For this repository you don't need any datasets. All you need is trained model.
Is there a script to download the data set too. I noticed you have it in another git repo for detection. But why not in this. This one only downloads the model and classfiles from blob but no data files.
As you already found out there's another repo in my account which you can use for training with my dataset or using your own datasets. This repository is only for using model with Python web service and deploying it to Azure Web Apps.
Hope it helps! If you still have any questions just let me know :)
Hi Karol,
Thanks for the reply. Appreciate the detailed email. I followed the steps to see if the app runs locally on my machine. It runs but the links don't work. Do I have to use Postman too? In the website demo the links don't work so cant really see whats going on.
Any hints on that.
I have already trained and tested my own data set using the documentation. So won't be following your second repo. I am doing this as a volunteer project for my company and wanted to detect only the classes I gave, in short not to detect all the objects but detect only what I want.
I am at beginner level when it comes to programming in of python with flask, so need help on making the demo work.
Regard,
Bhagyashree Patil
From: Karol Żak notifications@github.com Sent: Sunday, November 5, 2017 1:24 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
Hi @bpatil16https://github.com/bpatil16 ! First things first: this repository only shows how to use (already trained) model and expose it as a RESTful Python web service. It DOES NOT show how to train your own model. If you would like to train YOUR own model you may use my other repohttps://github.com/karolzak/CNTK-Hotel-pictures-classificator. You should specifically check out Use with custom datasethttps://github.com/karolzak/CNTK-Hotel-pictures-classificator#5-use-with-custom-dataset part of documentation there.
To use this repo for YOU OWN model you should do the following steps:
C.CNTK.IMAGE_WIDTH = 1000 __C.CNTK.IMAGE_HEIGHT = 1000 C.CNTK.NUM_CHANNELS = 3
So answering your questions:
So I was following your github repo. I want to know what the purpose of .temp folder used by the webservice. Temp folder is used by web service to temporary store images while evaluating them and plotting results.
I specifically want to know which folder are you storing the positive/negative and test images. generally its set up in the config.py file as __C.CNTK.MAP_FILE_PATH = parameter, its missing in the config.py file for this git repo. For this repository you don't need any datasets. All you need is trained model.
Is there a script to download the data set too. I noticed you have it in another git repo for detection. But why not in this. This one only downloads the model and classfiles from blob but no data files. As you already found out there's another repo in my account which you can use for training with my dataset or using your own datasets. This repository is only for using model with Python web service and deploying it to Azure Web Apps.
Hope it helps! If you still have any questions just let me know :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342006988, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52HWfMrVsALDvUFnnqTD-0jj1cy_Iks5sziepgaJpZM4QSPO7.
@bpatil16 links don't work in web browser because they are meant to be used with HTTP POST requests. To use them properly and get a response you need to send a proper POST request. I use Postman for that but it can be anything basically :)
To make it work with my demo your Postman request should look something like this (everything important is marked with red):
So my Python web service will wait for request and then will try to find an image with "file" key in a body of that request:
@app.route('/hotelidentifier/api/v1.0/evaluate/returnimage', methods=['POST'])
def return_image():
file_upload = request.files['file']
....
Of course this is just how I wrote my Python web service and you can do it totally differently, but yeah, this is how it works now.
Hope it helps! :)
Hi Zak
Please ignore my previous email that time my trained model and class file was not pushed to Azure website so I was getting your class labels on my image. Sorry about that.
I did copy my trained model and class map txt file to the CNTKModels folder and changes the parameter and tried running the app.py to see if it works locally I get this error (Swig Director error) Any clues what it is?
(C:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py35) C:\local\CNTK2\cntk\Examples\Image\CNTK-Python-WebApp\Code>python app.py
Thanks for all the help!
Bhagyashree
From: Karol Żak notifications@github.com Sent: Sunday, November 5, 2017 1:24 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
Hi @bpatil16https://github.com/bpatil16 ! First things first: this repository only shows how to use (already trained) model and expose it as a RESTful Python web service. It DOES NOT show how to train your own model. If you would like to train YOUR own model you may use my other repohttps://github.com/karolzak/CNTK-Hotel-pictures-classificator. You should specifically check out Use with custom datasethttps://github.com/karolzak/CNTK-Hotel-pictures-classificator#5-use-with-custom-dataset part of documentation there.
To use this repo for YOU OWN model you should do the following steps:
C.CNTK.IMAGE_WIDTH = 1000 __C.CNTK.IMAGE_HEIGHT = 1000 C.CNTK.NUM_CHANNELS = 3
So answering your questions:
So I was following your github repo. I want to know what the purpose of .temp folder used by the webservice. Temp folder is used by web service to temporary store images while evaluating them and plotting results.
I specifically want to know which folder are you storing the positive/negative and test images. generally its set up in the config.py file as __C.CNTK.MAP_FILE_PATH = parameter, its missing in the config.py file for this git repo. For this repository you don't need any datasets. All you need is trained model.
Is there a script to download the data set too. I noticed you have it in another git repo for detection. But why not in this. This one only downloads the model and classfiles from blob but no data files. As you already found out there's another repo in my account which you can use for training with my dataset or using your own datasets. This repository is only for using model with Python web service and deploying it to Azure Web Apps.
Hope it helps! If you still have any questions just let me know :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342006988, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52HWfMrVsALDvUFnnqTD-0jj1cy_Iks5sziepgaJpZM4QSPO7.
Hi @bpatil16
If I understand correctly:
My assumption is that there might be some problem with dependencies versions. Specifically with CNTK.
Please run above command in Anaconda command prompt (same env from where you're running app.py
) and send me the output:
pip list
Please also check this:
version.txt
file from C:\local\CNTK2
folder and let me know what you have there.Hi Karol,
This is out put of pip list. Ahh I used cntk 2.2 to train my model and downgraded pillow to 4.0. So I need to change cntk to 2.2 wheel in requirements.txt. is there any where else I need to change ? Thanks for help as I am developing my own web interface based on my code but taking your deployment.cmd file.
alabaster (0.7.10) args (0.1.0) Babel (2.5.1) bleach (1.5.0) boost (0.1) click (6.7) clint (0.5.1) cmake (0.8.0) cntk (2.2) colorama (0.3.9) cycler (0.10.0) decorator (4.1.2) dlib (18.17.100) docutils (0.14) easydict (1.6) entrypoints (0.2.3) Flask (0.12.2) future (0.16.0) gym (0.5.2) h5py (2.6.0) html5lib (0.9999999) imageio (2.1.1) imagesize (0.7.1) ipykernel (4.6.1) ipython (6.1.0) ipython-genutils (0.2.0) ipywidgets (6.0.0) itsdangerous (0.24) jedi (0.10.2) Jinja2 (2.9.6) jsonschema (2.6.0) jupyter (1.0.0) jupyter-client (5.1.0) jupyter-console (5.2.0) jupyter-core (4.3.0) Keras (2.0.6) MarkupSafe (1.0) Mastodon.py (1.1.1) matplotlib (1.5.3) mistune (0.7.4) nbconvert (5.2.1) nbformat (4.4.0) nbsphinx (0.2.14) networkx (1.11) notebook (5.0.0) numpy (1.11.2) olefile (0.44) opencv-python (3.2.0) pandas (0.19.1) pandas-datareader (0.2.1) pandocfilters (1.4.2) path.py (10.3.1) pickleshare (0.7.4) PIL (2.0+dummy) Pillow (4.0.0) pip (9.0.1) pkginfo (1.4.1) prompt-toolkit (1.0.15) protobuf (3.2.0) py (1.4.34) pydot-ng (1.0.0) pygame (1.9.3) pyglet (1.2.4) Pygments (2.2.0) pyparsing (2.2.0) pytest (3.0.3) python-dateutil (2.6.1) pytz (2017.2) PyYAML (3.12) pyzmq (16.0.2) qtconsole (4.3.1) requests (2.14.2) requests-file (1.4.1) requests-toolbelt (0.8.0) scikit-image (0.12.3) scikit-learn (0.18.1) scipy (0.18.1) seaborn (0.7.1) setuptools (27.2.0) simplegeneric (0.8.1) six (1.10.0) snowballstemmer (1.2.1) Sphinx (1.5.4) sphinx-rtd-theme (0.2.4) SQLAlchemy (1.1.14) testpath (0.3) Theano (0.9.0) tornado (4.5.2) traitlets (4.3.2) twine (1.8.1) wcwidth (0.1.7) Werkzeug (0.12.2) wheel (0.29.0) widgetsnbextension (3.0.2) win-unicode-console (0.5)
From: Karol Żak notifications@github.com Sent: Tuesday, November 7, 2017 12:39 AM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
Hi @bpatil16https://github.com/bpatil16
If I understand correctly:
My assumption is that there might be some problem with dependencies versions. Specifically with CNTK. Please run above command in Anaconda command prompt (same env from where you're running app.py) and send me the output:
pip list
Also, let me know which version of CNTK you used to train YOUR model?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342412310, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52J7DRLe0O7iZ7Ue5rEt-nBLeqc3aks5s0BcrgaJpZM4QSPO7.
Hi Karol,
I need to make your interface work locally first. Do I need to downgrade to cntk 2.1 for your code to work or is there somewhere to change the code to make it work locally not on web service with cntk2.2.
I know that requirement.txt comes in picture only for pushing it to web service.
Thanks,
Bhagyashree
From: Karol Żak notifications@github.com Sent: Tuesday, November 7, 2017 12:39 AM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
Hi @bpatil16https://github.com/bpatil16
If I understand correctly:
My assumption is that there might be some problem with dependencies versions. Specifically with CNTK. Please run above command in Anaconda command prompt (same env from where you're running app.py) and send me the output:
pip list
Also, let me know which version of CNTK you used to train YOUR model?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342412310, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52J7DRLe0O7iZ7Ue5rEt-nBLeqc3aks5s0BcrgaJpZM4QSPO7.
Hi @bpatil16
Thanks for info!
To be honest I never tried to run my code with CNTK 2.2 so I have no idea how it behaves... My best suggestion for now would be to train your model and run this sample fully with CNTK 2.1, Eventually I will try to make it work with CNTK 2.2 anyway, just don't know when I will find time for that..
Regarding requirements.txt
, you can also use it locally to install all the dependencies in your environment, try running this:
pip install -r requirements.txt
I followed your read me in git and pushed all my code to wwwroot folder in website. I see following in console in web app on azure
Directory of D:\home\site\wwwroot
11/07/2017 11:54 PM
python run_faster_rcnn.py D:\home\site\wwwroot Traceback (most recent call last): File "run_faster_rcnn.py", line 9, in
import numpy as np ImportError: No module named numpy
But all my python modules are in folder d:\home\python354x64\lib\site-packages how do I invoke the python cnrk environment to run my run_faster_rcnn.py command line in web service?
I want to test if my program is running as my website link it timing out with 500 error in browser. Any hints! hopefully this will be my last question.
I have also add following line in my run_fast_rcnn.py file
os.environ['PATH'] = r'D:\home\python354x64;' + os.environ['PATH']
Thanks,
Bhagyashree
From: Karol Żak notifications@github.com Sent: Tuesday, November 7, 2017 1:28 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
To be honest I never tried to run my code with CNTK 2.2 so I have no idea how it behaves... My best suggestion for now would be to train your model and run this sample fully with CNTK 2.1, Eventually I will try to make it work with CNTK 2.2 anyway, just don't know when I will find time for that..
Regarding requirements.txt, you can also use it locally to install all the dependencies in your environment, try running this:
pip install -r requirements.txt
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342628017, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52LaujcnLQFT4pibj4m_oCBxlJqM4ks5s0MtlgaJpZM4QSPO7.
@bpatil16
python run_faster_rcnn.py
then even though you have your custom Python env installed, this command will use some kind of root/default env of python on web apps and I bet if you type in pip list
in that command line you won't find numpy
module there.
You should try to explicitly say that you want to use your specific environment. Try using this instead:
D:\home\python354x64\python.exe run_faster_rcnn.py
web.config
looks like? I think you don't have any entry point for your webserver.
Take a look at my web.config:
Line marked with red color, points out webserver to run app.py
script which is my simple RESTful web service written using Flask module. Check this tutorial if you want to learn more about itI assume you don't have this one set up properly an thus your web server returns a timeout.
Everything is web.config file is like you highlighted. I found where my code is failing.
Its failing at load_model() function in cntk. I wanted to know if you need to zip the cntk dll and load then on azure. I noticed that you loaded only the cntk wheel for python in requirements.txt. What about the dlls?
I saw this another GitHub below
https://github.com/ilkarman/Azure-WebApp-w-CNTK
[https://avatars2.githubusercontent.com/u/20063954?s=400&v=4]https://github.com/ilkarman/Azure-WebApp-w-CNTK
ilkarman/Azure-WebApp-w-CNTK - GitHubhttps://github.com/ilkarman/Azure-WebApp-w-CNTK github.com Azure-WebApp-w-CNTK - Deployment template for Azure WebApp, CNTK, Python 3 (x64) and sample model
where he says that zip the dll
:: 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.
Please let me know if this is done in your deployment file or I have to do it
Thanks, Bhagyashree
From: Karol Żak notifications@github.com Sent: Wednesday, November 8, 2017 12:01 AM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
@bpatil16https://github.com/bpatil16
python run_faster_rcnn.py
then even though you have your custom Python env installed, this command will use some kind of root/default env of python on web apps and I bet if you type in pip list in that command line you won't find numpy module there. Try using this instead:
D:\home\python354x64\python.exe run_faster_rcnn.py
This should explicitly say that we want to use this specific environment.
I assume you don't have this one set up properly an thus your web server returns a timeout.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342739603, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52DT7kUJeOUImDat9FiShfTD2HWL9ks5s0V_MgaJpZM4QSPO7.
@bpatil16
Well, I know this other repository and I even based my scripts on that project but I modified it and used a bit different approach:
In my deploy.cmd
I have this:
:: 4. Install packages
echo Pip install requirements.
echo "Installing requirements"
%PYTHON_EXE% -m pip install -r requirements.txt
And in my requirements.txt
I specified CNTK 2.1 wheel and that pretty much solves it for me:
https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl
In your case, if you trained your model with CNTK 2.2 you should point out to CNTK 2.2 wheel, so:
https://cntk.ai/PythonWheel/CPU-Only/cntk-2.2-cp35-cp35m-win_amd64.whl
Please go to your Azure Web App KUDU cmd console and type in this:
D:\home\python354x64\python.exe -m pip list
Show me the output and we will see what's wrong with your Python environment
If you don't know how to access KUDU you can do it like this:
More about using KUDU with Azure can be found here
The command you gave doesn't work but I know that the Load_model() comes from the cntk.ops.functions module which is present on Azure in this path D:\home\python354x64\Lib\site-packages\cntk\ops.
So I have no clue now why I get error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Well I think things are present in my env but the server is timing out to load such a big file --- this may sound rubbish talk
Below is part of my code in run_fastercnn.py file and it stops at last line to Load_model()
@app.route('/', methods=['POST']) def my_form_post(): text = request.form['text']
cfg = get_configuration()
prepare(cfg, False)
cfg['TRAINED_MODEL_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "PretrainedModels",
cfg["MODEL"].TRAINED_MODEL_FILE)
trained_model = load_model(cfg['TRAINED_MODEL_PATH'])
From: Karol Żak notifications@github.com Sent: Wednesday, November 8, 2017 2:35 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
Well, I know this other repository and I even based my scripts on that project but I modified it and used a bit different approach: In my deploy.cmd I have this:
:: 4. Install packages echo Pip install requirements. echo "Installing requirements" %PYTHON_EXE% -m pip install -r requirements.txt
And in my requirements.txt I specified CNTK 2.1 wheel and that pretty much solves it for me:
https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl
In your case, if you trained your model with CNTK 2.2 you should point out to CNTK 2.2 wheel, so:
https://cntk.ai/PythonWheel/CPU-Only/cntk-2.2-cp35-cp35m-win_amd64.whl
Please go to your Azure Web App console and type in this:
D:\home\python354x64\python.exe pip list
Show me the output and we will see what's wrong with your Python environment
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-342984196, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52PsLaxtrvGy9GTYFQJqs-yi2-V7hks5s0iyygaJpZM4QSPO7.
I don't have your project so can't really tell where is the problem. I would definitely double check if everything is ok with Python env and if you have CNTK 2.2 installed. This project works for me so I don't see why it shouldn't work for your model also. Model is big, yes but it loads perfectly for me...
I created my website in S1 Plan I don't think that should be the problem though... I have also uploaded cntk2.2 wheel.
From: Karol Żak notifications@github.com Sent: Wednesday, November 8, 2017 4:43 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
I don't have your project so can't really tell where is the problem. I would definitely double check if everything is ok with Python env and if you have CNTK 2.2 installed. This project works for me so I don't see why it shouldn't work for your model also. Model is big, yes but it loads perfectly for me...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343010229, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52ImmZItS1vbUXuA89vLQKI3tURKAks5s0kqtgaJpZM4QSPO7.
so do you not need the cntk binaries in the cntk.zip folder to run your model? I wonder how come its working with just the cntk python wheel. Because your deployment code is missing below code.
:: Utility Functions :: ----------------- :InstallCNTK pushd "%DEPLOYMENT_TARGET%" echo "Downloading CNTK" curl %CNTK_BIN% > cntk.zip unzip cntk.zip echo "Extracted binaries ..." rm cntk.zip echo "Setting CNTK PATH" set CNTK_HOME=%DEPLOYMENT_TARGET%\cntk set PATH=%CNTK_HOME%;%PATH%
echo "Installing python wheel" %PYTHON_EXE% -m pip install %CNTK_WHEEL% %PYTHON_EXE% -c "import cntk;print(cntk.version)" popd goto :EOF
You only work with the wheel. I wonder if that is the problem. How do I tell in program to grab the functions.py file where the load_model() is defined.
Main program is in the wwwroot directory set environment to this folder
os.environ['PATH'] = r'D:\home\python354x64;' + os.environ['PATH'] import numpy as np import cntk from cntk.ops.functions import load_model
Still it doesn't load it.
I might just try rerunning your model and see how its loading model. I have come to complete stop. I can't send you my project as I am not storing the models in blob yet, otherwise I wud have sent the project.
come to complete stop from here 😞
Thanks though for all help and replying to my emails. thanks for your time
Bhagyashree
From: Karol Żak notifications@github.com Sent: Wednesday, November 8, 2017 4:43 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
I don't have your project so can't really tell where is the problem. I would definitely double check if everything is ok with Python env and if you have CNTK 2.2 installed. This project works for me so I don't see why it shouldn't work for your model also. Model is big, yes but it loads perfectly for me...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343010229, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52ImmZItS1vbUXuA89vLQKI3tURKAks5s0kqtgaJpZM4QSPO7.
@bpatil16
Installing CNTK wheel with pip
should be just enough to load the model and run evaluation. So in my project you don't need to upload CNTK.zip.
Be sure to write import os
before setting os.environ['PATH']
value, but I assume you did that.
Also try one more thing:
instead of this from cntk.ops.functions import load_model
use this from cntk import load_model
do you my any chance know which program prints this line
Selected CPU as the process wide default device.
As it may not find cpu on azure may be that's the problem. I went to functions.py file in the cntl\ops but can't find it there. If you know which program it is please let me know. I think that's the problem.
Thanks
Bhagyashree
From: Karol Żak notifications@github.com Sent: Wednesday, November 8, 2017 11:59 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
@bpatil16https://github.com/bpatil16 Installing CNTK wheel with pip should be just enough to load the model and run evaluation. So in my project you don't need to upload CNTK.zip.
Be sure to write import os before setting os.environ['PATH'] value, but I assume you did that.
Also try one more thing: instead of this from cntk.ops.functions import load_model use this from cntk import load_model
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343075769, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52E44m65eC8UH1Chies1Eyg0w0q-uks5s0rDvgaJpZM4QSPO7.
@bpatil16
This message comes from load_model
function from cntk module. It basically says that it chosen CPU for all the heavy processing. But it's good, it means that CNTK libs are there and they are doing something.
What seems to be the error message now?
When I run on azure I don’t get that message as it’s running in azure. I get error 500 in browser. So that’s what I think the problem or my program can’t locate cntk from python site packages. It’s either of two not finding cntk or not selectin cpu on cntk or timeout before it finds cntk
Sent from my iPhone
On Nov 9, 2017, at 11:37 AM, Karol Żak notifications@github.com<mailto:notifications@github.com> wrote:
@bpatil16https://github.com/bpatil16 This message comes from load_model function from cntk module. It basically says that it chosen CPU for all the heavy processing. But it's good, it means that CNTK libs are there and they are doing something. What seems to be the error message now?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343267733, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52L3hZhti2t5SK3H0kWgap-r-7YBqks5s01SQgaJpZM4QSPO7.
I am going to remove flask code and run my faster cnn programs on kudu console to see if I get that message. If I get error I will let you know :-)
Sent from my iPhone
On Nov 9, 2017, at 11:37 AM, Karol Żak notifications@github.com<mailto:notifications@github.com> wrote:
@bpatil16https://github.com/bpatil16 This message comes from load_model function from cntk module. It basically says that it chosen CPU for all the heavy processing. But it's good, it means that CNTK libs are there and they are doing something. What seems to be the error message now?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343267733, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52L3hZhti2t5SK3H0kWgap-r-7YBqks5s01SQgaJpZM4QSPO7.
So here is the problem: My program run perfectly on kudu console. So I have the right environment on azure. But when I run in it browser by clicking the azure web app website it gives error 500. So I commented the code which calls evaluate and then the gui works.
I am attaching my code. Why does the #evaluate_faster_rcnn(cfg, text) function when uncommented give error 500 in web browser? Is it the flask code ? Can you please check if my web config is ok. I have a feeling its the main program.
Thanks again
Bhagyashree
From: Karol Żak notifications@github.com Sent: Thursday, November 9, 2017 11:37 AM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
@bpatil16https://github.com/bpatil16 This message comes from load_model function from cntk module. It basically says that it chosen CPU for all the heavy processing. But it's good, it means that CNTK libs are there and they are doing something. What seems to be the error message now?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343267733, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52L3hZhti2t5SK3H0kWgap-r-7YBqks5s01SQgaJpZM4QSPO7.
import os os.environ['PATH'] = r'D:\home\python354x64;' + os.environ['PATH'] import numpy as np import cntk from cntk.ops.functions import load_model import time from FasterRCNN_train import prepare, train_faster_rcnn, store_eval_model_with_native_udf from FasterRCNN_eval import compute_test_set_aps, FasterRCNN_Evaluator from utils.config_helpers import merge_configs from utils.plot_helpers import plot_test_set_results
from flask import Flask, render_template, request app = Flask(name)
def get_configuration():
from FasterRCNN_config import cfg as detector_cfg
# for VGG16 base model use: from utils.configs.VGG16_config import cfg as network_cfg
# for AlexNet base model use: from utils.configs.AlexNet_config import cfg as network_cfg
#
from utils.configs.AlexNet_config import cfg as network_cfg
#from utils.configs.VGG16_config import cfg as network_cfg
# for Pascal VOC 2007 data set use: from utils.configs.Pascal_config import cfg as dataset_cfg
# for the Grocery data set use: from utils.configs.Grocery_config import cfg as dataset_cfg
#from utils.configs.Grocery_config import cfg as dataset_cfg
from utils.configs.MyDataSet_config import cfg as dataset_cfg
return merge_configs([detector_cfg, network_cfg, dataset_cfg])
def evaluate_faster_rcnn(cfg, text):
model_path = cfg['TRAINED_MODEL_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)), "PretrainedModels",
cfg["MODEL"].TRAINED_MODEL_FILE)
print("Stored eval model at %s" % model_path)
trained_model = load_model(cfg['TRAINED_MODEL_PATH'])
eval_results = compute_test_set_aps(trained_model, cfg)
#write AP results to output
for class_name in eval_results: print('AP for {:>15} = {:.4f}'.format(class_name, eval_results[class_name]))
print('Mean AP = {:.4f}'.format(np.nanmean(list(eval_results.values()))))
#Plot results on test set images
if cfg.VISUALIZE_RESULTS:
num_eval = min(cfg["DATA"].NUM_TEST_IMAGES, 100)
results_folder = os.path.join(cfg.OUTPUT_PATH, cfg["DATA"].DATASET)
evaluator = FasterRCNN_Evaluator(trained_model, cfg)
plot_test_set_results(evaluator, num_eval, results_folder, cfg, text)
#return text
@app.route('/') def my_form(): return render_template('my_form.html')
@app.route('/', methods=['POST']) def my_form_post():
text = request.form['text']
cfg = get_configuration()
prepare(cfg, False)
#evaluate_faster_rcnn(cfg, text)
return text
if name == 'main': HOST = os.environ.get('SERVER_HOST', 'localhost') try: PORT = int(os.environ.get('SERVER_PORT', '5000')) except ValueError: PORT = 5000 app.run(HOST, PORT)
Hi Karol
I switched the debug mode on in flask and I got the error below. So now I want to know the model you use for evaluate is that the one fron OUTPUT folder which gets saved after training. Where did you get the evaluate model from?
builtins.ValueError
ValueError: Cannot load the model D:\home\site\wwwroot\PretrainedModels\Obj.model that is neither a file nor a byte buffer.
Thanks,
Shree
I solved that error my folder was not in right place. Now I get another error when installing matplotlip 1.5.3 doesn't come with Tkinter so how will I put it there?
ImportError: No module named 'tkinter'
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1997, in call
return self.wsgi_app(environ, start_response)
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
* File "D:\home\python354x64\lib\site-packages\flask_compat.py", line 33, in reraise
raise value
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
* File "D:\home\python354x64\lib\site-packages\flask_compat.py", line 33, in reraise
raise value
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
* File "D:\home\python354x64\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functionsrule.endpoint
* File "D:\home\site\wwwroot\run_faster_rcnn.py", line 79, in my_form_post
return json.dumps(evaluate_faster_rcnn(cfg, text))
* File "D:\home\site\wwwroot\run_faster_rcnn.py", line 61, in evaluate_faster_rcnn
plot_test_set_results(evaluator, num_eval, results_folder, cfg, text)
* File "D:\home\site\wwwroot\utils\plot_helpers.py", line 139, in plot_test_set_results
from matplotlib.pyplot import imsave
*
File "D:\home\python354x64\lib\site-packages\matplotlib\pyplot.py", line 114, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
* File "D:\home\python354x64\lib\site-packages\matplotlib\backends__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
*
File "D:\home\python354x64\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 6, in
from matplotlib.externals.six.moves import tkinter as Tk
* File "D:\home\python354x64\lib\site-packages\matplotlib\externals\six.py", line 90, in get
result = self._resolve()
* File "D:\home\python354x64\lib\site-packages\matplotlib\externals\six.py", line 113, in _resolve
return _import_module(self.mod)
* File "D:\home\python354x64\lib\site-packages\matplotlib\externals\six.py", line 80, in _import_module
import(name)
ImportError: No module named 'tkinter'
From: bhagyashree patil bhagyashreepatil@hotmail.com Sent: Thursday, November 9, 2017 4:09 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Value error
Hi Karol
I switched the debug mode on in flask and I got the error below. So now I want to know the model you use for evaluate is that the one fron OUTPUT folder which gets saved after training. Where did you get the evaluate model from?
builtins.ValueError
ValueError: Cannot load the model D:\home\site\wwwroot\PretrainedModels\Obj.model that is neither a file nor a byte buffer.
Thanks,
Shree
@bpatil16 Glad to see you're moving forward with your project :)
I think I know where this problem comes from. In "Code highlights" part of my Readme.md file I mentioned that in order to plot results on images, you need to use matplotlib
in a special non GUI mode. Check this out:
While working with headless server environment (non-GUI) such as Azure Web Apps you need to change the default mode of matpotlib module to not rely on GUI
# this is important when deploying to headless server environment (non-GUI)
###################################################
import matplotlib
# force headless backend, or set 'backend' to 'Agg'
# in your ~/.matplotlib/matplotlibrc
matplotlib.use('Agg')
import matplotlib.pyplot
# force non-interactive mode, or set 'interactive' to False
# in your ~/.matplotlib/matplotlibrc
from matplotlib.pyplot import imsave
matplotlib.pyplot.ioff()
###################################################
You need to find the file with script responsible for plotting images and change your regular import matplotlib
into somthing like above
Hi Karol,
I did that and now all my images are tagged properly and in output folder. But at the end I get this error
The specified CGI application encountered an error and the server terminated the process.
Thanks,
Shree
From: Karol Żak notifications@github.com Sent: Friday, November 10, 2017 1:19 AM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
@bpatil16https://github.com/bpatil16 Glad to see you're moving forward with your project :)
I think I know where this problem comes from. In "Code highlights" part of my Readme.md file I mentioned that in order to plot results on images, you need to use matplotlib in a special non GUI mode. Check this out:
While working with headless server environment (non-GUI) such as Azure Web Apps you need to change the default mode of matpotlib module to not rely on GUI
################################################### import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
from matplotlib.pyplot import imsave matplotlib.pyplot.ioff() ###################################################
You need to find the file with script responsible for plotting images and change your regular import matplotlib into somthing like above
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343420582, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52MnPnzsFdWkgzS0HJdpY0_upPBn4ks5s1BU2gaJpZM4QSPO7.
Hi Karol,
The below code in evaluate.py file throws the error: The specified CGI application encountered an error and the server terminated the process.
print("Plotting results from Faster R-CNN model for image.")
# evaluate single image
_, cntk_img_input, dims = load_resize_and_pad(imgPath, img_shape[2], img_shape[1])
dims_input = np.array(dims, dtype=np.float32)
dims_input.shape = (1,) + dims_input.shape
output = frcn_eval.eval({frcn_eval.arguments[0]: [cntk_img_input], frcn_eval.arguments[1]: dims_input})
out_dict = dict([(k.name, k) for k in output])
out_cls_pred = output[out_dict['cls_pred']][0]
out_rpn_rois = output[out_dict['rpn_rois']][0]
out_bbox_regr = output[out_dict['bbox_regr']][0]
I kept commenting my code in plot_helpers.py in the plot_test_set_results unti I hit the line :
out_cls_pred, out_rpn_rois, out_bbox_regr, dims = evaluator.process_image_detailed(img_path)
The code for evaluator.process_image_detailed is below which is similar to your code in evaluate.py file. Do you know what CGI application it is calling ? I cant figure out?
Thanks Shree
From: Karol Żak notifications@github.com Sent: Friday, November 10, 2017 1:19 AM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
@bpatil16https://github.com/bpatil16 Glad to see you're moving forward with your project :)
I think I know where this problem comes from. In "Code highlights" part of my Readme.md file I mentioned that in order to plot results on images, you need to use matplotlib in a special non GUI mode. Check this out:
While working with headless server environment (non-GUI) such as Azure Web Apps you need to change the default mode of matpotlib module to not rely on GUI
################################################### import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
from matplotlib.pyplot import imsave matplotlib.pyplot.ioff() ###################################################
You need to find the file with script responsible for plotting images and change your regular import matplotlib into somthing like above
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-343420582, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52MnPnzsFdWkgzS0HJdpY0_upPBn4ks5s1BU2gaJpZM4QSPO7.
@bpatil16
I'm not sure but it seems like it's related to plotting images so most probable thing here is that you're trying to use matplotlib
in a headless server environment (Azure Web Apps) and so the program crashes.
In your plot_helpers.py
change your regular matplotlib
imports into something like this:
# this is important when deploying to headless server environment (non-GUI)
###################################################
import matplotlib
# force headless backend, or set 'backend' to 'Agg'
# in your ~/.matplotlib/matplotlibrc
matplotlib.use('Agg')
import matplotlib.pyplot
# force non-interactive mode, or set 'interactive' to False
# in your ~/.matplotlib/matplotlibrc
from matplotlib.pyplot import imsave
matplotlib.pyplot.ioff()
###################################################
Let me know how it goes
I have already done this. I realized if I reduce the number of test images my web service doesn't give the cgi error, its the timing issue to processes many files.
Apart from that now I am trying to upload my test images in blob process them and again upload it to blob maybe..
There is something like flask azure storage. Have you used it? I see only one link on internet about it
https://pypi.python.org/pypi/Flask-Azure-Storage/0.1.1
I have to figure out how to connect to blob from my webapp in flask ... do you know anything more about this?
Flask-Azure-Storage 0.1.1 : Python Package Indexhttps://pypi.python.org/pypi/Flask-Azure-Storage/0.1.1 pypi.python.org Flask extension that provides integration with Azure Storage
From: Karol Żak notifications@github.com Sent: Tuesday, November 14, 2017 11:43 PM To: karolzak/CNTK-Python-Web-Service-on-Azure Cc: bpatil16; Mention Subject: Re: [karolzak/CNTK-Python-Web-Service-on-Azure] Where are the dataset files (#1)
@bpatil16https://github.com/bpatil16
I'm not sure but it seems like it's related to plotting images so most probable thing here is that you're trying to use matplotlib in a headless server environment (Azure Web Apps) and so the program crashes. In your plot_helpers.py change your regular matplotlib imports into something like this:
################################################### import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
from matplotlib.pyplot import imsave matplotlib.pyplot.ioff() ###################################################
Let me know how it goes
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-344510995, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52LTGk6YXdosuQBxLLP2uZrLvT0OQks5s2pYHgaJpZM4QSPO7.
@bpatil16 Well, there are ready to use modules for Python and other languages from Microsoft: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-python-how-to-use-blob-storage Why not using that?
BTW. Azure Web Apps with Python REST API is not the best approach to perform batch classification of images. You should rather set it up on some kind of VM with GPU for faster processing
I have seen this page but I want my app in flask to connect to blob process images and dump them back in blob let me see if it works. There is something called flask cloudy written by mit folks which can be used
Sent from my iPhone
On Nov 17, 2017, at 5:34 AM, Karol Żak notifications@github.com<mailto:notifications@github.com> wrote:
@bpatil16https://github.com/bpatil16 Well, there are ready to use modules for Python and other languages from Microsoft: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-python-how-to-use-blob-storage Why not using that?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/karolzak/CNTK-Python-Web-Service-on-Azure/issues/1#issuecomment-345244860, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATQ52AipHkzQoMMpKRw1HFfjqpsI0Kejks5s3Ys9gaJpZM4QSPO7.
It should work like a charm :) doesn’t matter that you’re using flask or sth else
Hi I have simulated object detection on my machine using fasterRcnn now I want to expose it to webservice in Azure. So I was following your github repo. I want to know what the purpose of .temp folder used by the webservice. I specifically want to know which folder are you storing the positive/negative and test images. generally its set up in the config.py file as __C.CNTK.MAP_FILE_PATH = parameter, its missing in the config.py file for this git repo. Is there a script to download the data set too. I noticed you have it in another git repo for detection. But why not in this. This one only downloads the model and classfiles from blob but no data files. Thanks in advance for help.