Microsoft Cognitive Toolkit Mac

Visual Studio 2019 for Mac A free and full-featured solution for individual developers to create applications for Android, iOS, macOS, cloud and the web. Please see the Release Notes for more information. Microsoft Cognitive Toolkit, previously known as CNTK and sometimes styled as The Microsoft Cognitive Toolkit, is a deprecated deep learning framework developed by Microsoft Research. Microsoft Cognitive Toolkit describes neural networks as a series of computational steps via a directed graph. Comparison of deep learning software; ML.NET. Details: Microsoft Dynamics is a line of integrated, adaptable business management solutions that enable your people to make important business decisions with greater confidence. Microsoft Dynamics works like and with familiar Microsoft software-easing adoption and reducing the risks inherent with implementing a.

-->

You can set up CNTK as a Docker Container on your Linux system.

There are two ways of using CNTK Docker Containers:

  • CNTK Docker Containers
    • Using CNTK Images published at Docker Hub

Using CNTK Images published at Docker Hub

We host public CNTK Images at Docker Hub. See complete list of Images available at CNTK Repositories page at Docker Hub. We currently host only runtime configurations. Runtime configuration corresponds to an environment with CNTK Binary package installed and configured. This configuration contains neither CNTK source code, nor the prerequisites required to build CNTK.

Note, that you need NVIDIA Docker to use CNTK GPU-enabled images.

Standard Docker commands are used to get the image:

to get the latest official release image, which today means latest available GPU runtime configuration. You also can get the latest development nightly image:

To get a specific configuration you need to add a tag. E.g.

will get you CNTK 2.7 CPU runtime configuration set up for Python 3.5.

If you are unfamiliar with Docker, read sections below at this page.

Using Docker container to run CNTK Jupyter Notebook tutorials

You can use CNTK Docker containers to run CNTK Jupyter Notebooks in your local environment.

We assume that you have already pulled the required images from Docker Hub. In the example below we will use GPU configuration. If you are using CPU configuration, then in the commands below replace all occurrences of nvidia-docker with docker.

First create and start a CNTK container in detached mode with IP port exposed (we use port 8888 which is default for Jupyter Notebook application):

Now start Jupyter Notebook server in your Docker container:

In your terminal you will see the console output of Jupyter Notebooks server. This output would contain a line like this:
http://0.0.0.0:8888/?token=082684fbe2b43eebd72583c301c05072084173d0ac06a4d7

Copy the token displayed (in our example 082684fbe2b43eebd72583c301c05072084173d0ac06a4d7).

Now you may access CNTK Jupyter Notebooks using the IP address of the machine where you are running the Docker container. I.e. if your machine address is 192.168.1.1 then to access CNTK Notebooks open a browser window and go tohttp://192.168.1.1:8888.

Note, that during the first run Jupyter Notebook application will ask for a password or token. Use the token you have saved above.

To stop the Jupyter Notebook server send Ctrl-C sequence in the terminal where you have Jupiter Notebook server console output and confirm shutting down the server. Note that it will not stop the Docker container itself. To stop the container use the command:
docker stop cntk-jupyter-notebooks

WARNING! The commands above will expose Jupyter Notebooks application to everybody who can access the IP address of the machine where you are running the Docker container.

Building CNTK Docker Images

You can build and run CNTK using the same container and this is a recommended approach to reproduce our reference configuration.

First you need to install docker. It is highly recommended to follow the installation process in the official docker documentation. Versions that come with your Linux distribution might be outdated and will not work with nvidia-docker (which you may need to install in addition to docker if you plan to build and run the GPU image from within the same container). You should also follow the instructions in the optional section titled creating a docker group.

The correspondent Docker files are in the CNTK Repository at https://github.com/Microsoft/CNTK/tree/release/latest/Tools/docker

To build a docker image with CNTK and all its dependencies, simply clone the CNTK repository, navigate to CNTK/Tools/docker and use the Dockerfile you want to build from (CPU or GPU). For example, to build CNTK's GPU docker image, execute:

The -f <path/to/Dockerfile> argument is required because some patches, common for both CPU and GPU dockerfiles, need to be applied on SWIG source code.If you receive errors that say Could not resolve 'archive.ubuntu.com'you will need to provide docker with the IP addresses of your DNS servers.First find the IP addresses of your DNS servers using, for example, the command

or the command

Let's say that the IPs of your DNS servers are a.b.c.d and x.y.z.w.Then

Microsoft cognitive toolkit cntk
  • on Ubuntu 15.10 and later (or other Linux that uses systemd)modify /lib/systemd/system/docker.service so that the dockerdaemon is started with the additional options--dns a.b.c.d --dns x.y.z.w
  • on Ubuntu 15.04 and earlier (or other Linux that does not use systemd)edit /etc/default/docker so that the lineis uncommented and contains the IP addresses of your DNS servers.

Note: some companies block public DNS servers such as 8.8.8.8and 8.8.4.4. You can try using them but if the problem persistsyou should try to use the DNS server IP addresses reported by nm-tool/nmcli.

Restart the docker daemon via

and delete any docker images that where created with the wrong DNS settings.To delete all docker images do

To delete all docker containers do

Now try again

If you have a GPU you'll want to test if you can access it through a docker container once you have built the image. Try this command:

If it works, you are done. If it doesn't, it means that there is a mismatch between the CUDA version and/or drivers installed on your host and in your CNTK docker image. In particular, the mismatch is between the kernel-mode NVidia driver module and the user-mode module (which is a shared lib) and this happens if the version on the host does not exactly match the version in the container. Fortunately this is easy to fix. Just install nvidia-docker and use it exactly like docker (no need to rebuild the image).

This should work and enables CNTK to use the GPU from inside a docker container. If this does not work, search the Issues section on the nvidia-docker GitHub -- many solutions are already documented. Note that if your /usr and /var directories are in different partitions, you will need some extra steps like here. To get an interactive shell to a container that will not be automatically deleted after you exit do

If you want to share your data and configurations between the host (your machine or VM) and the container in which you are using CNTK, use the -v option, e.g.

This will make /project1/data from the host visible as /data in the container, and /project1/config as /config. Such isolation reduces the chances of your containerized experiments overwriting or using wrong data.

-->

Microsoft Cognitive Toolkit Cntk

If you want to build manually CNTK from source code on Windows using Visual Studio 2017, this page is for you.

If you are looking for any other kind of support to setup a CNTK build environment or installing CNTK on your system, you should go here instead.

Note

This page assumes that you are trying to build CNTK's master branch.

64-bit OS

CNTK requires a 64-bit Windows installation. We tested the build process on Windows 8.1, Windows 10, and Windows Server 2012 R2 and later. Other environments are not officially supported. For compatibility issues check CNTK Production Build and Test configuration.

Environment Variables and Components

Building CNTK on your system requires the definition and configuration of various environment variables. An overview of environment variables used by the Windows build of CNTK can be found on this page. In addition, this page gives an overview of required and optional components for building CNTK as well as their default install location.

Visual Studio 2017

Install Microsoft Visual Studio 2017 for Windows. A link to the download can be found here.

The Community Version of Visual Studio 2017 is sufficient to build CNTK.

During the installation process, please select 'Universal Windows Platform development', '.NET desktop development', 'Desktop development with C++', and 'Python development' workloads:

Besides, On the individual components screen make sure you add 'VC++ 2017 version 15.4 v14.11 toolset' and 'Visual C++ runtime for UWP' to your installation:

Lastly, add 'Windows 10 SDK (10.0.16299.0) for Desktop C++ [x86 and x64]':

Preexisting Visual Studio 2017 installation

You are required to have the 'VC++ 2017 version 15.4 v14.11 toolset', 'Visual C++ runtime for UWP' and 'Windows 10 SDK (10.0.16299.0) for Desktop C++ [x86 and x64]' installed on your system. To check open the Windows 'Control Panel -> Programs -> Programs and Features' and select 'Visual Studio Community 2017' from the list of installed programs. This will start the Visual Studio setup again and allows you to make sure the aforementioned components are installed on your system (see picture above).

Note

If VS2017INSTALLDIR environment variable was not set by the Visual Studio installer, set it manually. The exact installation directory depends on both the version (2017 in this case) and offering (Community, Enterprise, etc) of Visual Studio, according to the following pattern: C:Program Files (x86)Microsoft Visual Studio<version><offering>.

For Visual Studio 2017 Enterprise edition, run:

For Visual Studio 2017 Community edition, run:

Git

Git is required to work with the CNTK code base. You may use the following tools:

  • Git for Windows. This is the standard command line client for Git, which we will use on this page to describe the enlisting in the CNTK repository.

  • A Git client is available as a part of the Visual Studio 2017 installation. Read the blog post Microsoft Application Lifecycle Management about using the built-in Git client.

Enlisting in the CNTK GitHub repository

Here we assume you installed Git for Windows. We assume you installed Git using the default options in the Git installer (Especially 'Use Git from the Windows Command Prompt' and with the option 'Checkout Windows-style, commit UNIX-style line endings' at the 'Configuring line endings' prompt enabled.

Create a clone of the CNTK source code in c:reposcntk directory. If you prefer a different location, you will need to adjust the commands accordingly.

Open a standard windows command shell, and execute these command

This puts all the required source code for a standard build onto your system. If you plan on making modifications to the CNTK code, you should read the information on Developing and Testing.

The submodule Multiverso is used to enable DataParallelASGD for training. If you don't need DataParallelASGD support, then add the environment variable CNTK_ENABLE_ASGD and set its value to false. E.g. run this in a CMD prompt, and then reopen your CMD shell(s) and Visual Studio to pick up the change:

MKL

The default CNTK math library is the Intel Math Kernel Library (Intel MKL). Follow this page to install it

MKL-DNN

  • Download MKL-DNN source and build with MKL_PATH as target path. Check build instructions in Setup MKL-DNN on Windows

  • Set the environment variable MKL_PATH to the directory, e.g.:

MS-MPI

Install version 7 (7.0.12437.6) of Microsoft MPI (MS-MPI) from this download page, marked simply as 'Version 7' in the page title. Click on the Download button, and then select both msmpisdk.msi and MSMpiSetup.exe.

Boost

Follow these steps to install the Boost Library on your system:

Microsoft cognitive toolkit tutorial
  • Download and install Boost version 1.60 (you need the msvc-14.0 binaries) from this download location on Sourceforge.
  • Set the environment variable BOOST_INCLUDE_PATH to your Boost installation, e.g.:
  • Set the environment variable BOOST_LIB_PATH to the Boost libraries, e.g.:
  • To integrate the Boost test framework into Visual Studio you can install a runner for Boost tests in Visual Studio from the Visual Studio Gallery.

Protobuf

You need a version of Protobuf 3.1.0 compiled for CNTK. You can compile this version by yourself, or use an already (precompiled) prepared version of Protobuf 3.1.0 (described on this page). If you want to build the Protobuf library for CNTK on your system, you can find the details here

Download the ZIP file containing the precompiled version of Protobuf for CNTK from this location

Extract the archive to a folder on your local disk, e.g. to C:localprotobuf-3.1.0-vs15 and set the environment variable PROTOBUF_PATH pointing to that location, e.g.:

GPU Specific Packages

This section outlines the packages you need to setup in order for CNTK to leverage NVIDIA GPUs.

If you do NOT intend to use any GPUs with CNTK and will rely on the CPU only, you may skip directly to the next general section. Otherwise proceed to this page.

Set the environment variable CUDNN_PATH pointing to that location, e.g.:

Set the environment variable CUB_PATH pointing to that location, e.g.:

OPTIONAL. SWIG.

If you want to take advantage of CNTK from Python, you will need to install SWIG. SWIG is also a requirement to build the CNTK Evaluation libraries (for C#/.NET or Java).

Please download the version SWIG 3.0.10 from this site.

Extract the archive to a folder on your local disk, e.g. to C:localswigwin-3.0.10 and set the environment variable SWIG_PATH pointing to that location, e.g.:

Microsoft Cognitive Toolkit Mac

Quick installation check: If you followed the instruction above and used the same paths, the command dir C:localswigwin-3.0.10swig.exe will succeed and show one file.

OPTIONAL. OpenCV

CNTK 2.2 requires Open Source Computer Vision (OpenCV) to be installed but it is optional for CNTK 2.3. Follow this page for further steps.

Set the environment variable OPENCV_PATH_V31 pointing to the OpenCV build folder, e.g.

Quick installation check: If you followed the instruction above and used the same paths, the command dir C:localOpencv3.1.0build will succeed.

OPTIONAL. zlib and libzip

If you plan to build the CNTK Image Reader you require zlib and libzip libraries.

zlib and libzip

The ZLib and LibZip are distributed in source code, you will need to recompile these packages, you can also use a precompiled version we created for your convenience (described in this section). To build the libraries yourself, you find detailed instructions here

Download the ZIP file containing the precompiled version of libzip/zlib compression library for CNTK from this location

Extract the archive to a folder on your local disk, e.g. to C:localzlib-vs15 and set the environment variable ZLIB_PATH pointing to that location, e.g.:

Quick installation check: If you followed the instruction above and used the same paths, the command dir C:localzlib-vs15bin will succeed and show a couple of DLLs.

OPTIONAL. Anaconda Python Installation

If you plan to build CNTK with Python support, install SWIG if you have not done so yet. Also, you will need a Python environment. We use Anaconda Python for our default Python installation.

If you do not have an Anaconda installation: install Anaconda Python for Windows.You can follow the standard configuration given in the install program (InstallationType=JustMe; AddToPath=No; RegisterPython=No). In the following we assume you installed Python Anaconda3 4.1.1 into C:localAnaconda3-4.1.1-Windows-x86_64.

OPTIONAL. CNTK UWP Build

If you want to build the CNTK Evaluation Library for UWP you need to follow the additional installation steps described here.

CNTK Python environments

CNTK supports Python 2.7, Python 3.5 and Python 3.6. We recommend you create a dedicated environment in your Python installation to work with CNTK. This way CNTK and the installed supporting packages won't impact any other Python project. We provide several files (yml-files) containing the description of required Python packages. The packages are located in the scriptsinstallwindows directory inside your CNTK clone. Please select the file matching your targeted Python version.

Python versionFilename
Python 2.7conda-windows-cntk-py27-environment.yml
Python 3.5conda-windows-cntk-py35-environment.yml
Python 3.6conda-windows-cntk-py36-environment.yml

As an example we create a Python 3.5 environment in an environment named cntk-py35. If you want a different environment name, please adjust the following steps accordingly. If you want to create a Python 2.7 or Python 3.6 environment, please adjust the name of the YML to match the Python version you intend to use.

The following assumes you cloned the CNTK source code from GitHub into the directory c:reposcntk.

  • To create a new conda environment (e.g. cntk-py35) and activate it, run the following commands from the Windows command shell:

If you have an environment (e.g. cntk-py35) you can update it with the latest required packages with the following commands:

CNTK Environment Variables for Python

Before you start the build of CNTK and build the Python libraries for CNTK, you need to set/define environment variables CNTK_PY.._PATH and PYTHONPATH

CNTK_PY.._PATH

Set up build environment variables for your Python environment (choose at least one that applies):

If you followed the installation so far, this would mean

The value for the CNTK_PY36_PATH, CNTK_PY35_PATH, or CNTK_PY27_PATH environment variables can be determined by running inconda ..activate cmd.exe [name-or-path-of-your-environment]

PYTHONPATH

PYTHONPATH sets the paths to the places Python will look for modules to import. If you build CNTK, you need to add the output path of the build process to this environment variable. If you cloned CNTK into c:reposcntk this will be

OPTIONAL. Java

To build the Java bindings for the CNTK Evaluation library, install the SWIG tool if you have not done so yet. Also, a Java Development Kit (JDK) is required. Currently we use 64 bit JDK 8 (JDK Version 1.8.0_131).

Set the environment variable JAVA_HOME to point to the directory of Java installation. The following setting assumes that you have installed JDK 1.8.0_131 to C:localjdk1.8.0_131:

Uninstall previous CNTK versions

If you previously installed any version of the CNTK Python package on your machine, uninstall it by first removing any CNTK related paths in the PYTHONPATH environment variable. Do: echo %PYTHONPATH% to see its current value, and then use the setx command to set PYTHONPATH such that the CNTK related paths are gone. If that makes PYTHONPATH empty, so be it.

Do the uninstall: pip uninstall cntk

This concludes the installation portion. Let's continue with building CNTK

Building CNTK

Currently there's a compatibility issue between CUDA 9 and default VCTools in Visual Studio 2017. CNTK requires VCTools 14.11 to build with CUDA 9. To do that:

  • Open Command Prompt
  • call '%VS2017INSTALLDIR%VCAuxiliaryBuildvcvarsall.bat' amd64 -vcvars_ver=14.11

This will set VCTools to the CUDA 9 compatible version. From the Command Prompt, start CNTK.sln in the root of the cloned CNTK project from GitHub. If CNTK.sln runs with the default CUDA9-incompatible version of VCTools, there will be build errors like '1>c:program filesnvidia gpu computing toolkitcudav9.0includecrt/host_config.h(133): fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!'

If you just changed and environment variable, you should close any already opened Visual Studio instance, otherwise the content of changed environment variables will not be reflected inside Visual Studio.

  • Right-click the CNTK Solution in Solution Explorer and select Properties
  • In the opened window select Configuration Properties and press Configuration Manager... button
  • In Configuration Manager select the desired configuration:
    • Debug or Release
    • GPU or CPU-only. CPU-only configurations are explicitly named. All other configurations imply GPU usage (i.e. Release means Release. GPU enabled mode)
    • You should always select CPU-only configurations if you have NOT installed the components required for GPU configurations

Build the CNTK solution. The components created by the build process are dependent on the prerequisites you installed, for details the page detailing Windows Environment Variables should be consulted.

If you build Python modules note:

  • Python modules are only created in the Release configuration
  • This will build the CNTK Python module inside bindingspythoncntk and also produce a package (.whl) in a subfolder Python of your build output folder (e.g., x64ReleasePython)
  • Make sure your path includes the build output folder (e.g., x64Release), and that PYTHONPATH includes the bindingspython directory. This is contrary to the setup shown for the Pip package installation, here we will load the CNTK module from the CNTK repository clone, not as an installed package in your Python environment, hence also the difference in setting up PYTHONPATH.

Test of CNTK build functionality

To ensure that CNTK is working properly in your system, you can quickly run an example from theHello World - Logistic Regression tutorial.This example trains a simple network and can be directed to use either CPU or GPU, which helps quickly ensure that CNTK isfunctioning properly.

Below we assume that the CNTK repository is cloned to c:reposcntk and buildx64release was used as a sub-directory for the (Release) build.

  • Open Command Prompt
  • Provide the path to the CNTK binaries (via Environment Variable or for Command Prompt session using the first command below) and change to the TutorialsHelloWorld-LogisticRegression directory:

First try the example:

If the sample runs, i.e. if there are no error messages, you will get an output related first to reading the configuration, followedby the output of the actual network training.

Trying CNTK with GPU

If you built CNTK for GPU usage, try using GPU by executing the following command:

Near the beginning of the output you should see a line confirming a GPU was used:

Note that GPU ID may be different. The deviceId parameter defines what processor to use for computation.

  • deviceId=-1 means use CPU. Default value
  • deviceId=X where X is an integer >=0 means use GPU X, i.e. deviceId=0 means GPU 0, etc.
  • deviceId=auto means use GPU, select GPU automatically

Microsoft Cognitive Toolkit C#

Trying the CNTK Python API

We assume that you created a CNTK Python environment (either through the install script or manually. Open a command prompt and activate your CNTK Python environment, e.g., by executing

As a quick test change into the TutorialsNumpyInterop folder and run python FeedForwardNet.py. After training you should see an output similar to this:

Debugging CNTK source code in Visual Studio

Microsoft Cognitive Toolkit Mac Iphone

  • If you want to use Python Tools, CNTK, and Visual Studio Code, see this blog.
  • If you want to use Python Tools, CNTK, and Visual Studio, see here
  • To debug BrainScript in CNTK with Visual Studio, follow the steps here.

Contributing to CNTK code

Cognitive Toolkit

If you plan modifications to the code you should read the information on Developing and Testing.

Cntk Python

Links