Archive for the ‘MICrosoft AI framework’ Category

Learning and working with CNTK(2.4)

February 22, 2018

I just got introduced to CNTK and this my attempt to learn the CNTK from the ground up.

I liked python with CNTK to run on my laptop core i5 with no Discrete graphic card. You dont need an Azure subscription to use Microsoft CNTK!! But if you dont have a discrete Graphics card (dGPU) then it may help to speed things up :

So I used link here to install and setup CNTK

https://docs.microsoft.com/en-us/cognitive-toolkit/setup-windows-python?tabs=cntkpy24

 From the very beginning

Install python 3.6

https://www.python.org/ftp/python/3.6.4/python-3.6.4.exe

C:\WINDOWS\system32>python –version
Python 3.6.4

 

 

You will also need to install anaconda

Anaconda3

We have been testing CNTK with Anaconda3 4.1.1 (64-bit) and Python versions 2.7 and 3.5, as well as Anaconda3 4.3.1 with Python version 3.6. If you do not have a Anaconda3 Python installation, install Anaconda3 4.1.1 Python for Windows (64-bit).

Below we assume Anaconda is installed and that it is listed before any other Python installations in your PATH. If you plan on using a GPU enabled version of CNTK, you will need a CUDA 9 compliant graphics card and up-to-date graphics drivers installed on your system.

Above link has all the next steps..

Anaconda for python 3.6

https://repo.continuum.io/archive/Anaconda3-5.1.0-Windows-x86_64.exe

 

install with python 3.6 with CPU only

C:\>pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.4-cp36-cp36m-win_amd64.whl

 Collecting cntk==2.4 from https://cntk.ai/PythonWheel/CPU-Only/cntk-2.4-cp36-cp36m-win_amd64.whl
 Downloading https://cntk.ai/PythonWheel/CPU-Only/cntk-2.4-cp36-cp36m-win_amd64.whl (71.4MB)
 100% |████████████████████████████████| 71.5MB 17kB/s
 Collecting scipy>=0.17 (from cntk==2.4)
 Downloading scipy-1.0.0-cp36-none-win_amd64.whl (30.8MB)
 100% |████████████████████████████████| 30.8MB 35kB/s
 Collecting numpy>=1.11 (from cntk==2.4)
 Downloading numpy-1.14.0-cp36-none-win_amd64.whl (13.4MB)
 100% |████████████████████████████████| 13.4MB 78kB/s
 Installing collected packages: numpy, scipy, cntk
 Successfully installed cntk-2.4 numpy-1.14.0 scipy-1.0.0

GPU version 

C:\WINDOWS\system32>pip install https://cntk.ai/PythonWheel/GPU-1bit-SGD/cntk-2.4-cp36-cp36m-win_amd64.whl

cntk-2.0-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.

 

Installation failed – the reason was because I needed to install anaconda version matchin python 3.6 before the CNTK install.  After I did that it worked.

C:\>pip install https://cntk.ai/PythonWheel/GPU/cntk-2.4-cp36-cp36m-win_amd64.whl

Collecting cntk==2.4 from https://cntk.ai/PythonWheel/GPU/cntk-2.4-cp36-cp36m-win_amd64.whl
 Downloading https://cntk.ai/PythonWheel/GPU/cntk-2.4-cp36-cp36m-win_amd64.whl (436.3MB)
 100% |████████████████████████████████| 436.3MB 44kB/s
Requirement already satisfied: scipy>=0.17 in c:\users\dell\anaconda3\lib\site-packages (from cntk==2.4)
Requirement already satisfied: numpy>=1.11 in c:\users\dell\anaconda3\lib\site-packages (from cntk==2.4)
Installing collected packages: cntk
Successfully installed cntk-2.4
Quick installation test

A quick test that the installation succeeded can be done by querying the CNTK version

C:\Python27>python -c “import cntk; print(cntk.__version__)”

2.4

 

 

C:\Users\Dell>conda create –name cntk-py36 python=3.6 numpy scipy h5py jupyter

Fetching package metadata .......
 Solving package specifications: ..........

Package plan for installation in environment C:\Users\Dell\Anaconda3\envs\cntk-py36:

The following packages will be downloaded:

package | build
 ---------------------------|-----------------
 mkl-2017.0.3 | 0 126.3 MB
 vs2015_runtime-14.0.25420 | 0 2.0 MB
 vc-14 | 0 703 B
 icu-57.1 | vc14_0 34.2 MB
 jpeg-9b | vc14_0 304 KB
 openssl-1.0.2l | vc14_0 5.1 MB
 python-3.6.2 | 0 31.5 MB
 zlib-1.2.11 | vc14_0 119 KB
 certifi-2016.2.28 | py36_0 214 KB
 colorama-0.3.9 | py36_0 22 KB
 decorator-4.1.2 | py36_0 15 KB
 entrypoints-0.2.3 | py36_0 10 KB
 ipython_genutils-0.2.0 | py36_0 38 KB
 jedi-0.10.2 | py36_2 246 KB
 jsonschema-2.6.0 | py36_0 103 KB
 libpng-1.6.30 | vc14_1 503 KB
 markupsafe-1.0 | py36_0 28 KB
 mistune-0.7.4 | py36_0 148 KB
 numpy-1.13.1 | py36_0 3.6 MB
 pandocfilters-1.4.2 | py36_0 13 KB
 path.py-10.3.1 | py36_0 51 KB
 pygments-2.2.0 | py36_0 1.4 MB
 pyzmq-16.0.2 | py36_0 539 KB
 simplegeneric-0.8.1 | py36_1 8 KB
 sip-4.18 | py36_0 270 KB
 six-1.10.0 | py36_0 20 KB
 testpath-0.3.1 | py36_0 15 KB
 tornado-4.5.2 | py36_0 631 KB
 wcwidth-0.1.7 | py36_0 24 KB
 wheel-0.29.0 | py36_0 129 KB
 wincertstore-0.2 | py36_0 14 KB
 h5py-2.7.0 | np113py36_0 720 KB
 html5lib-0.9999999 | py36_0 178 KB
 pickleshare-0.7.4 | py36_0 11 KB
 prompt_toolkit-1.0.15 | py36_0 340 KB
 python-dateutil-2.6.1 | py36_0 238 KB
 qt-5.6.2 | vc14_6 55.5 MB
 scipy-0.19.1 | np113py36_0 13.1 MB
 setuptools-36.4.0 | py36_1 534 KB
 traitlets-4.3.2 | py36_0 130 KB
 bleach-1.5.0 | py36_0 22 KB
 ipython-6.1.0 | py36_0 1.0 MB
 jinja2-2.9.6 | py36_0 392 KB
 jupyter_core-4.3.0 | py36_0 112 KB
 pip-9.0.1 | py36_1 1.7 MB
 pyqt-5.6.0 | py36_2 4.5 MB
 jupyter_client-5.1.0 | py36_0 139 KB
 nbformat-4.4.0 | py36_0 137 KB
 ipykernel-4.6.1 | py36_0 137 KB
 nbconvert-5.2.1 | py36_0 411 KB
 jupyter_console-5.2.0 | py36_0 52 KB
 notebook-5.0.0 | py36_0 5.4 MB
 qtconsole-4.3.1 | py36_0 197 KB
 widgetsnbextension-3.0.2 | py36_0 2.0 MB
 ipywidgets-6.0.0 | py36_0 65 KB
 jupyter-1.0.0 | py36_3 4 KB
 ------------------------------------------------------------
 Total: 294.4 MB

The following NEW packages will be INSTALLED:

bleach: 1.5.0-py36_0
 certifi: 2016.2.28-py36_0
 colorama: 0.3.9-py36_0
 decorator: 4.1.2-py36_0
 entrypoints: 0.2.3-py36_0
 h5py: 2.7.0-np113py36_0
 hdf5: 1.8.15.1-vc14_4
 html5lib: 0.9999999-py36_0
 icu: 57.1-vc14_0
 ipykernel: 4.6.1-py36_0
 ipython: 6.1.0-py36_0
 ipython_genutils: 0.2.0-py36_0
 ipywidgets: 6.0.0-py36_0
 jedi: 0.10.2-py36_2
 jinja2: 2.9.6-py36_0
 jpeg: 9b-vc14_0
 jsonschema: 2.6.0-py36_0
 jupyter: 1.0.0-py36_3
 jupyter_client: 5.1.0-py36_0
 jupyter_console: 5.2.0-py36_0
 jupyter_core: 4.3.0-py36_0
 libpng: 1.6.30-vc14_1
 markupsafe: 1.0-py36_0
 mistune: 0.7.4-py36_0
 mkl: 2017.0.3-0
 nbconvert: 5.2.1-py36_0
 nbformat: 4.4.0-py36_0
 notebook: 5.0.0-py36_0
 numpy: 1.13.1-py36_0
 openssl: 1.0.2l-vc14_0
 pandocfilters: 1.4.2-py36_0
 path.py: 10.3.1-py36_0
 pickleshare: 0.7.4-py36_0
 pip: 9.0.1-py36_1
 prompt_toolkit: 1.0.15-py36_0
 pygments: 2.2.0-py36_0
 pyqt: 5.6.0-py36_2
 python: 3.6.2-0
 python-dateutil: 2.6.1-py36_0
 pyzmq: 16.0.2-py36_0
 qt: 5.6.2-vc14_6
 qtconsole: 4.3.1-py36_0
 scipy: 0.19.1-np113py36_0
 setuptools: 36.4.0-py36_1
 simplegeneric: 0.8.1-py36_1
 sip: 4.18-py36_0
 six: 1.10.0-py36_0
 testpath: 0.3.1-py36_0
 tornado: 4.5.2-py36_0
 traitlets: 4.3.2-py36_0
 vc: 14-0
 vs2015_runtime: 14.0.25420-0
 wcwidth: 0.1.7-py36_0
 wheel: 0.29.0-py36_0
 widgetsnbextension: 3.0.2-py36_0
 wincertstore: 0.2-py36_0
 zlib: 1.2.11-vc14_0

Proceed ([y]/n)? y

Fetching packages ...
 mkl-2017.0.3-0 100% |###############################| Time: 0:00:38 3.44 MB/s
 vs2015_runtime 100% |###############################| Time: 0:00:00 3.71 MB/s
 vc-14-0.tar.bz 100% |###############################| Time: 0:00:00 128.68 kB/s
 icu-57.1-vc14_ 100% |###############################| Time: 0:00:12 2.92 MB/s
 jpeg-9b-vc14_0 100% |###############################| Time: 0:00:00 3.68 MB/s
 openssl-1.0.2l 100% |###############################| Time: 0:00:01 3.70 MB/s
 python-3.6.2-0 100% |###############################| Time: 0:00:08 3.68 MB/s
 zlib-1.2.11-vc 100% |###############################| Time: 0:00:00 2.04 MB/s
 certifi-2016.2 100% |###############################| Time: 0:00:00 1.84 MB/s
 colorama-0.3.9 100% |###############################| Time: 0:00:00 813.05 kB/s
 decorator-4.1. 100% |###############################| Time: 0:00:00 830.97 kB/s
 entrypoints-0. 100% |###############################| Time: 0:00:00 1.22 MB/s
 ipython_genuti 100% |###############################| Time: 0:00:00 2.30 MB/s
 jedi-0.10.2-py 100% |###############################| Time: 0:00:00 3.71 MB/s
 jsonschema-2.6 100% |###############################| Time: 0:00:00 3.56 MB/s
 libpng-1.6.30- 100% |###############################| Time: 0:00:00 3.69 MB/s
 markupsafe-1.0 100% |###############################| Time: 0:00:00 1.88 MB/s
 mistune-0.7.4- 100% |###############################| Time: 0:00:00 3.53 MB/s
 numpy-1.13.1-p 100% |###############################| Time: 0:00:01 3.69 MB/s
 pandocfilters- 100% |###############################| Time: 0:00:00 1.84 MB/s
 path.py-10.3.1 100% |###############################| Time: 0:00:00 2.92 MB/s
 pygments-2.2.0 100% |###############################| Time: 0:00:00 3.69 MB/s
 pyzmq-16.0.2-p 100% |###############################| Time: 0:00:00 3.71 MB/s
 simplegeneric- 100% |###############################| Time: 0:00:00 1.12 MB/s
 sip-4.18-py36_ 100% |###############################| Time: 0:00:00 1.02 MB/s
 six-1.10.0-py3 100% |###############################| Time: 0:00:00 1.54 MB/s
 testpath-0.3.1 100% |###############################| Time: 0:00:00 1.84 MB/s
 tornado-4.5.2- 100% |###############################| Time: 0:00:00 3.75 MB/s
 wcwidth-0.1.7- 100% |###############################| Time: 0:00:00 1.47 MB/s
 wheel-0.29.0-p 100% |###############################| Time: 0:00:00 3.01 MB/s
 wincertstore-0 100% |###############################| Time: 0:00:00 1.25 MB/s
 h5py-2.7.0-np1 100% |###############################| Time: 0:00:00 3.74 MB/s
 html5lib-0.999 100% |###############################| Time: 0:00:00 4.14 MB/s
 pickleshare-0. 100% |###############################| Time: 0:00:00 1.64 MB/s
 prompt_toolkit 100% |###############################| Time: 0:00:00 3.76 MB/s
 python-dateuti 100% |###############################| Time: 0:00:00 3.87 MB/s
 qt-5.6.2-vc14_ 100% |###############################| Time: 0:00:16 3.53 MB/s
 scipy-0.19.1-n 100% |###############################| Time: 0:00:03 3.69 MB/s
 setuptools-36. 100% |###############################| Time: 0:00:00 3.81 MB/s
 traitlets-4.3. 100% |###############################| Time: 0:00:00 3.91 MB/s
 bleach-1.5.0-p 100% |###############################| Time: 0:00:00 2.24 MB/s
 ipython-6.1.0- 100% |###############################| Time: 0:00:00 3.71 MB/s
 jinja2-2.9.6-p 100% |###############################| Time: 0:00:00 3.84 MB/s
 jupyter_core-4 100% |###############################| Time: 0:00:00 3.32 MB/s
 pip-9.0.1-py36 100% |###############################| Time: 0:00:00 3.68 MB/s
 pyqt-5.6.0-py3 100% |###############################| Time: 0:00:01 2.62 MB/s
 jupyter_client 100% |###############################| Time: 0:00:00 3.44 MB/s
 nbformat-4.4.0 100% |###############################| Time: 0:00:00 3.18 MB/s
 ipykernel-4.6. 100% |###############################| Time: 0:00:00 3.05 MB/s
 nbconvert-5.2. 100% |###############################| Time: 0:00:00 2.42 MB/s
 jupyter_consol 100% |###############################| Time: 0:00:00 2.60 MB/s
 notebook-5.0.0 100% |###############################| Time: 0:00:01 3.69 MB/s
 qtconsole-4.3. 100% |###############################| Time: 0:00:00 3.41 MB/s
 widgetsnbexten 100% |###############################| Time: 0:00:00 3.69 MB/s
 ipywidgets-6.0 100% |###############################| Time: 0:00:00 3.25 MB/s
 jupyter-1.0.0- 100% |###############################| Time: 0:00:00 564.69 kB/s
 Extracting packages ...
 [ COMPLETE ]|##################################################| 100%
 Linking packages ...
 1 file(s) copied.############################## | 64%
 Active code page: 437
 [ COMPLETE ]|##################################################| 100%
 #
 # To activate this environment, use:
 # > activate cntk-py36
 #
 # To deactivate this environment, use:
 # > deactivate
 #

 

Installing Samples and Tutorials

We provide various samples and tutorials with CNTK. After you installed CNTK you can install the samples/tutorials and Jupyter notebooks. If you installed CNTK into a Python environment, make sure you activated the environment before running this command:

Install samples 

I highly recommend doing this step rather than downloadign them separately from Github. The reason is that when it install the samples it also install the prerequisites.

 

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\TransferLearning>C:\Users\Dell\AppData\Local\Programs\Python\Python36\python -m cntk.sample_installer

 
C:\Users\Dell\AppData\Local\Programs\Python\Python36\lib\runpy.py:125: RuntimeWarning: 'cntk.sample_installer' found in sys.modules after import of package 'cntk', but prior to execution of 'cntk.sample_installer'; this may result in unpredictable behaviour
 warn(RuntimeWarning(msg))
 INFO: retrieving https://cntk.ai/Samples/CNTK-Samples-2-4.zip

INFO: unzipping to directory CNTK-Samples-2-4

INFO: installing requirements

Collecting h5py>=2.6.0 (from -r CNTK-Samples-2-4\requirements.txt (line 1))
 Downloading h5py-2.7.1-cp36-cp36m-win_amd64.whl (2.3MB)
 100% |████████████████████████████████| 2.3MB 468kB/s
 Collecting jupyter>=1.0.0 (from -r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading jupyter-1.0.0-py2.py3-none-any.whl
 Collecting matplotlib>=1.5.3 (from -r CNTK-Samples-2-4\requirements.txt (line 3))
 Downloading matplotlib-2.1.2-cp36-cp36m-win_amd64.whl (8.7MB)
 100% |████████████████████████████████| 8.7MB 125kB/s
 Collecting pandas>=0.19.1 (from -r CNTK-Samples-2-4\requirements.txt (line 4))
 Downloading pandas-0.22.0-cp36-cp36m-win_amd64.whl (9.1MB)
 100% |████████████████████████████████| 9.1MB 128kB/s
 Collecting pandas-datareader>=0.2.1 (from -r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading pandas_datareader-0.6.0-py2.py3-none-any.whl (103kB)
 100% |████████████████████████████████| 112kB 3.3MB/s
 Collecting pillow>=3.4.2 (from -r CNTK-Samples-2-4\requirements.txt (line 6))
 Using cached Pillow-5.0.0-cp36-cp36m-win_amd64.whl
 Requirement already satisfied: pip>=8.1.2 in c:\users\dell\appdata\local\programs\python\python36\lib\site-packages (from -r CNTK-Samples-2-4\requirements.txt (line 7))
 Collecting seaborn>=0.7.1 (from -r CNTK-Samples-2-4\requirements.txt (line 8))
 Downloading seaborn-0.8.1.tar.gz (178kB)
 100% |████████████████████████████████| 184kB 3.3MB/s
 Collecting six>=1.10.0 (from -r CNTK-Samples-2-4\requirements.txt (line 9))
 Downloading six-1.11.0-py2.py3-none-any.whl
 Collecting gym>=0.5.2 (from -r CNTK-Samples-2-4\requirements.txt (line 10))
 Downloading gym-0.9.7.tar.gz (108kB)
 100% |████████████████████████████████| 112kB 3.3MB/s
 Requirement already satisfied: numpy>=1.7 in c:\users\dell\appdata\local\programs\python\python36\lib\site-packages (from h5py>=2.6.0->-r CNTK-Samples-2-4\requirements.txt (line 1))
 Collecting ipywidgets (from jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading ipywidgets-7.1.2-py2.py3-none-any.whl (68kB)
 100% |████████████████████████████████| 71kB 2.3MB/s
 Collecting ipykernel (from jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading ipykernel-4.8.2-py3-none-any.whl (108kB)
 100% |████████████████████████████████| 112kB 6.6MB/s
 Collecting jupyter-console (from jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading jupyter_console-5.2.0-py2.py3-none-any.whl
 Collecting qtconsole (from jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading qtconsole-4.3.1-py2.py3-none-any.whl (108kB)
 100% |████████████████████████████████| 112kB 2.2MB/s
 Collecting notebook (from jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading notebook-5.4.0-py2.py3-none-any.whl (8.0MB)
 100% |████████████████████████████████| 8.0MB 142kB/s
 Collecting nbconvert (from jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading nbconvert-5.3.1-py2.py3-none-any.whl (387kB)
 100% |████████████████████████████████| 389kB 1.6MB/s
 Collecting cycler>=0.10 (from matplotlib>=1.5.3->-r CNTK-Samples-2-4\requirements.txt (line 3))
 Downloading cycler-0.10.0-py2.py3-none-any.whl
 Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib>=1.5.3->-r CNTK-Samples-2-4\requirements.txt (line 3))
 Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
 100% |████████████████████████████████| 61kB 3.9MB/s
 Collecting python-dateutil>=2.1 (from matplotlib>=1.5.3->-r CNTK-Samples-2-4\requirements.txt (line 3))
 Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
 100% |████████████████████████████████| 194kB 3.3MB/s
 Collecting pytz (from matplotlib>=1.5.3->-r CNTK-Samples-2-4\requirements.txt (line 3))
 Using cached pytz-2018.3-py2.py3-none-any.whl
 Collecting wrapt (from pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading wrapt-1.10.11.tar.gz
 Collecting lxml (from pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading lxml-4.1.1-cp36-cp36m-win_amd64.whl (3.5MB)
 100% |████████████████████████████████| 3.6MB 186kB/s
 Collecting requests>=2.3.0 (from pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
 100% |████████████████████████████████| 92kB 5.9MB/s
 Collecting requests-file (from pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading requests_file-1.4.3-py2.py3-none-any.whl
 Collecting requests-ftp (from pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading requests-ftp-0.3.1.tar.gz
 Collecting pyglet>=1.2.0 (from gym>=0.5.2->-r CNTK-Samples-2-4\requirements.txt (line 10))
 Downloading pyglet-1.3.1-py2.py3-none-any.whl (1.0MB)
 100% |████████████████████████████████| 1.0MB 936kB/s
 Collecting widgetsnbextension~=3.1.0 (from ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading widgetsnbextension-3.1.4-py2.py3-none-any.whl (2.2MB)
 100% |████████████████████████████████| 2.2MB 471kB/s
 Collecting ipython>=4.0.0; python_version >= "3.3" (from ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading ipython-6.2.1-py3-none-any.whl (745kB)
 100% |████████████████████████████████| 747kB 334kB/s
 Collecting nbformat>=4.2.0 (from ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading nbformat-4.4.0-py2.py3-none-any.whl (155kB)
 100% |████████████████████████████████| 163kB 2.4MB/s
 Collecting traitlets>=4.3.1 (from ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
 100% |████████████████████████████████| 81kB 2.3MB/s
 Collecting jupyter-client (from ipykernel->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading jupyter_client-5.2.2-py2.py3-none-any.whl (88kB)
 100% |████████████████████████████████| 92kB 1.8MB/s
 Collecting tornado>=4.0 (from ipykernel->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading tornado-4.5.3-cp36-cp36m-win_amd64.whl (423kB)
 100% |████████████████████████████████| 430kB 1.6MB/s
 Collecting prompt-toolkit<2.0.0,>=1.0.0 (from jupyter-console->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading prompt_toolkit-1.0.15-py3-none-any.whl (247kB)
 100% |████████████████████████████████| 256kB 2.0MB/s
 Collecting pygments (from jupyter-console->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading Pygments-2.2.0-py2.py3-none-any.whl (841kB)
 100% |████████████████████████████████| 849kB 867kB/s
 Collecting ipython-genutils (from qtconsole->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
 Collecting jupyter-core (from qtconsole->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading jupyter_core-4.4.0-py2.py3-none-any.whl (126kB)
 100% |████████████████████████████████| 133kB 1.3MB/s
 Collecting Send2Trash (from notebook->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading Send2Trash-1.5.0-py3-none-any.whl
 Collecting jinja2 (from notebook->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading Jinja2-2.10-py2.py3-none-any.whl (126kB)
 100% |████████████████████████████████| 133kB 2.2MB/s
 Collecting terminado>=0.8.1 (from notebook->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading terminado-0.8.1-py2.py3-none-any.whl
 Collecting bleach (from nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading bleach-2.1.2-py2.py3-none-any.whl
 Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading pandocfilters-1.4.2.tar.gz
 Collecting testpath (from nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading testpath-0.3.1-py2.py3-none-any.whl (161kB)
 100% |████████████████████████████████| 163kB 3.3MB/s
 Collecting mistune>=0.7.4 (from nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading mistune-0.8.3-py2.py3-none-any.whl
 Collecting entrypoints>=0.2.2 (from nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading entrypoints-0.2.3-py2.py3-none-any.whl
 Collecting certifi>=2017.4.17 (from requests>=2.3.0->pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading certifi-2018.1.18-py2.py3-none-any.whl (151kB)
 100% |████████████████████████████████| 153kB 2.3MB/s
 Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.3.0->pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
 100% |████████████████████████████████| 143kB 1.8MB/s
 Collecting idna<2.7,>=2.5 (from requests>=2.3.0->pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading idna-2.6-py2.py3-none-any.whl (56kB)
 100% |████████████████████████████████| 61kB 1.1MB/s
 Collecting urllib3<1.23,>=1.21.1 (from requests>=2.3.0->pandas-datareader>=0.2.1->-r CNTK-Samples-2-4\requirements.txt (line 5))
 Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
 100% |████████████████████████████████| 133kB 2.7MB/s
 Collecting future (from pyglet>=1.2.0->gym>=0.5.2->-r CNTK-Samples-2-4\requirements.txt (line 10))
 Downloading future-0.16.0.tar.gz (824kB)
 100% |████████████████████████████████| 829kB 1.2MB/s
 Requirement already satisfied: setuptools>=18.5 in c:\users\dell\appdata\local\programs\python\python36\lib\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Collecting decorator (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading decorator-4.2.1-py2.py3-none-any.whl
 Collecting pickleshare (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading pickleshare-0.7.4-py2.py3-none-any.whl
 Collecting jedi>=0.10 (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading jedi-0.11.1-py2.py3-none-any.whl (250kB)
 100% |████████████████████████████████| 256kB 1.4MB/s
 Collecting colorama; sys_platform == "win32" (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading colorama-0.3.9-py2.py3-none-any.whl
 Collecting simplegeneric>0.8 (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading simplegeneric-0.8.1.zip
 Collecting jsonschema!=2.5.0,>=2.4 (from nbformat>=4.2.0->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading jsonschema-2.6.0-py2.py3-none-any.whl
 Collecting pyzmq>=13 (from jupyter-client->ipykernel->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading pyzmq-17.0.0-cp36-cp36m-win_amd64.whl (944kB)
 100% |████████████████████████████████| 952kB 981kB/s
 Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading wcwidth-0.1.7-py2.py3-none-any.whl
 Collecting MarkupSafe>=0.23 (from jinja2->notebook->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading MarkupSafe-1.0.tar.gz
 Collecting pywinpty>=0.5; os_name == "nt" (from terminado>=0.8.1->notebook->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading pywinpty-0.5.1-cp36-cp36m-win_amd64.whl (176kB)
 100% |████████████████████████████████| 184kB 1.6MB/s
 Collecting html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre (from bleach->nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading html5lib-1.0.1-py2.py3-none-any.whl (117kB)
 100% |████████████████████████████████| 122kB 2.4MB/s
 Collecting parso==0.1.1 (from jedi>=0.10->ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading parso-0.1.1-py2.py3-none-any.whl (91kB)
 100% |████████████████████████████████| 92kB 2.9MB/s
 Collecting webencodings (from html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre->bleach->nbconvert->jupyter>=1.0.0->-r CNTK-Samples-2-4\requirements.txt (line 2))
 Downloading webencodings-0.5.1-py2.py3-none-any.whl
 Installing collected packages: six, h5py, ipython-genutils, decorator, pickleshare, parso, jedi, traitlets, colorama, wcwidth, prompt-toolkit, pygments, simplegeneric, ipython, python-dateutil, pyzmq, jupyter-core, tornado, jupyter-client, ipykernel, jsonschema, nbformat, Send2Trash, MarkupSafe, jinja2, pywinpty, terminado, webencodings, html5lib, bleach, pandocfilters, testpath, mistune, entrypoints, nbconvert, notebook, widgetsnbextension, ipywidgets, jupyter-console, qtconsole, jupyter, cycler, pyparsing, pytz, matplotlib, pandas, wrapt, lxml, certifi, chardet, idna, urllib3, requests, requests-file, requests-ftp, pandas-datareader, pillow, seaborn, future, pyglet, gym
 Running setup.py install for simplegeneric ... done
 Running setup.py install for MarkupSafe ... done
 Running setup.py install for pandocfilters ... done
 Running setup.py install for wrapt ... done
 Running setup.py install for requests-ftp ... done
 Running setup.py install for seaborn ... done
 Running setup.py install for future ... done
 Running setup.py install for gym ... done
 Successfully installed MarkupSafe-1.0 Send2Trash-1.5.0 bleach-2.1.2 certifi-2018.1.18 chardet-3.0.4 colorama-0.3.9 cycler-0.10.0 decorator-4.2.1 entrypoints-0.2.3 future-0.16.0 gym-0.9.7 h5py-2.7.1 html5lib-1.0.1 idna-2.6 ipykernel-4.8.2 ipython-6.2.1 ipython-genutils-0.2.0 ipywidgets-7.1.2 jedi-0.11.1 jinja2-2.10 jsonschema-2.6.0 jupyter-1.0.0 jupyter-client-5.2.2 jupyter-console-5.2.0 jupyter-core-4.4.0 lxml-4.1.1 matplotlib-2.1.2 mistune-0.8.3 nbconvert-5.3.1 nbformat-4.4.0 notebook-5.4.0 pandas-0.22.0 pandas-datareader-0.6.0 pandocfilters-1.4.2 parso-0.1.1 pickleshare-0.7.4 pillow-5.0.0 prompt-toolkit-1.0.15 pyglet-1.3.1 pygments-2.2.0 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2018.3 pywinpty-0.5.1 pyzmq-17.0.0 qtconsole-4.3.1 requests-2.18.4 requests-file-1.4.3 requests-ftp-0.3.1 seaborn-0.8.1 simplegeneric-0.8.1 six-1.11.0 terminado-0.8.1 testpath-0.3.1 tornado-4.5.3 traitlets-4.3.2 urllib3-1.22 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-3.1.4 wrapt-1.10.11


Build a sample 

I got this error when I downloaded the samples from githuib. The environment wasnt setup correctly.

 

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\TransferLearning>py TransferLearning.py

 Traceback (most recent call last):
 File "TransferLearning.py", line 11, in <module>
 from pillow import Image
 ModuleNotFoundError: No module named 'pillow'

I tried installing image, pillow and PIL but that didnt help!

pip install pillow

 

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\TransferLearning>pip install image

Collecting image
Downloading image-1.5.19-py2.py3-none-any.whl
Requirement already satisfied: pillow in c:\users\dell\anaconda3\envs\cntk-py36\lib\site-packages (from image)
Collecting django (from image)
Downloading Django-2.0.2-py3-none-any.whl (7.1MB)
100% |████████████████████████████████| 7.1MB 148kB/s
Collecting pytz (from django->image)
Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
100% |████████████████████████████████| 512kB 973kB/s
Installing collected packages: pytz, django, image
Successfully installed django-2.0.2 image-1.5.19 pytz-2018.3

 

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\TransferLearning>conda install pillow

Fetching package metadata .......
 Solving package specifications: ..........

Package plan for installation in environment C:\Users\Dell\Anaconda3\envs\cntk-py36:

The following packages will be downloaded:

package | build
 ---------------------------|-----------------
 libtiff-4.0.6 | vc14_3 466 KB
 olefile-0.44 | py36_0 52 KB
 freetype-2.5.5 | vc14_2 627 KB
 pillow-4.2.1 | py36_0 971 KB
 ------------------------------------------------------------
 Total: 2.1 MB

The following NEW packages will be INSTALLED:

bzip2: 1.0.6-vc14_3
 freetype: 2.5.5-vc14_2
 libtiff: 4.0.6-vc14_3
 olefile: 0.44-py36_0
 pillow: 4.2.1-py36_0

Proceed ([y]/n)? y

Fetching packages ...
 libtiff-4.0.6- 100% |###############################| Time: 0:00:00 4.13 MB/s
 olefile-0.44-p 100% |###############################| Time: 0:00:00 2.47 MB/s
 freetype-2.5.5 100% |###############################| Time: 0:00:00 3.80 MB/s
 pillow-4.2.1-p 100% |###############################| Time: 0:00:00 3.78 MB/s
 Extracting packages ...
 [ COMPLETE ]|##################################################| 100%
 Linking packages ...
 [ COMPLETE ]|##################################################| 100%

 

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\TransferLearning>conda info pil

 Fetching package metadata .......

pil 1.1.7 py26_0
 ----------------
 file name : pil-1.1.7-py26_0.tar.bz2
 name : pil
 version : 1.1.7
 build number: 0
 build string: py26_0
 channel : defaults
 size : 746 KB
 date : 2014-01-01
 fn : pil-1.1.7-py26_0.tar.bz2
 license_family: Other
 md5 : ebf2863cd37405f13d6096d1981e188d
 priority : 1
 schannel : defaults
 url : https://repo.continuum.io/pkgs/free/win-64/pil-1.1.7-py26_0.tar.bz2
 dependencies:
 python 2.6*

pil 1.1.7 py27_0
 ----------------
 file name : pil-1.1.7-py27_0.tar.bz2
 name : pil
 version : 1.1.7
 build number: 0
 build string: py27_0
 channel : defaults
 size : 746 KB
 date : 2014-01-01
 fn : pil-1.1.7-py27_0.tar.bz2
 license_family: Other
 md5 : 05e217d1ecfa9636a92af6ea8cfbd409
 priority : 1
 schannel : defaults
 url : https://repo.continuum.io/pkgs/free/win-64/pil-1.1.7-py27_0.tar.bz2
 dependencies:
 python 2.7*

 

It still didnt fix it till I installed the CNTK samples.

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\TransferLearning>C:\Users\Dell\AppData\Local\Programs\Python\Python36\python TransferLearning.py

 Traceback (most recent call last):
 File "TransferLearning.py", line 200, in <module>
 try_set_default_device(gpu(0))
 File "C:\Users\Dell\AppData\Local\Programs\Python\Python36\lib\site-packages\cntk\internal\swig_helper.py", line 69, in wrapper
 result = f(*args, **kwds)
 File "C:\Users\Dell\AppData\Local\Programs\Python\Python36\lib\site-packages\cntk\device.py", line 96, in gpu
 return cntk_py.DeviceDescriptor.gpu_device(device_id)
 ValueError: Specified GPU device id (0) is invalid.

[CALL STACK]
 > CNTK::NDMask:: MaskedCount
 - CNTK::DeviceDescriptor:: GPUDevice
 - PyInit__cntk_py
 - PyCFunction_FastCallDict
 - PyObject_CallFunctionObjArgs
 - PyEval_EvalFrameDefault
 - Py_CheckFunctionResult
 - PyList_Size
 - PyEval_EvalFrameDefault
 - Py_CheckFunctionResult
 - PyObject_CallFunctionObjArgs
 - PyEval_EvalFrameDefault
 - Py_CheckFunctionResult
 - PyEval_EvalCodeEx
 - PyEval_EvalCode
 - PyArena_Free

 

This one Needs GPU hence the error

I commented out the following line in \CNTK-master\CNTK-master\Examples\Image\TransferLearning\Transferlearning.py to make it work on CPU. And then I realized that this will smoke my CPU :). And it was using GPU for a reason. Just search for GPU in the python code and comment it out.

#from cntk.device import try_set_default_device, gpu

# try_set_default_device(gpu(0))

Lets try another one

(cntk-py36) C:\Users\Dell\Downloads\CNTK-master\CNTK-master\Examples\Image\Classification\ConvNet\Python>C:\Users\Dell\AppData\Local\Programs\Python\Python36\python ConvNet_CIFAR10.py

 Selected CPU as the process wide default device.
 -------------------------------------------------------------------
 Build info:

Built time: Jan 31 2018 14:48:31
 Last modified date: Tue Jan 23 11:59:52 2018
 Build type: Release
 Build target: CPU-only
 With 1bit-SGD: no
 With ASGD: yes
 Math lib: mkl
 Build Branch: HEAD
 Build SHA1: a70455c7abe76596853f8e6a77a4d6de1e3ba76e
 MPI distribution: Microsoft MPI
 MPI version: 7.0.12437.6
 -------------------------------------------------------------------
 Training 1195594 parameters in 14 parameter tensors.

Learning rate per 1 samples: 0.0015625
 Momentum per 64 samples: 0.9

…(off it goes)

YAY IT WORKS!!!

I am going to cover more CNTK samples in the next blog. Happy learning

Advertisements