Skip to content

CNTK usage overview

Philipp Kranen edited this page Dec 21, 2015 · 33 revisions

To use CNTK you need to either download the executable binaries or download the source code and compile it on your machine ([details](Setup CNTK on your machine)). There are three main tasks (or actions) that are supported by CNTK:

  • Train - Define a network and train it to produce a trained model using training data
  • Evaluate - Test a trained model to assess its performance using test data
  • Deploy - Use a trained model, e.g. in your own solution, to classify new instances

A brief overview for each of these tasks is given below and pointers to a more detailed description are provided. In addition there other tasks that CNTK supports such as edit existing models and write node outputs to a file. An overview for those is provided on the [Advanced topics](Advanced topics overview) wiki page.

Training a model using CNTK

To train a model using CNTK you need to provide a configuration file as the first argument when calling the CNTK executable cntk configFile=yourExp.config (see also [examples](Simple2d example) for a detailed walk through) The following snippet provides an overview of the contents of a configuration file.

ModelDir = "../Models"
command = "TIMIT_TrainNDL"

TIMIT_TrainNDL = [
    action = "train"
    deviceId = "auto"
    modelPath = "$ModelDir$/timitModel.dnn"

    NDLNetworkBuilder = [...]
    SGD = [...]
    reader = [...]
]

The above code snippet defines a command called TIMIT_TrainNDL with action = "train". Other supported actions are for example test or write. The deviceId parameter specifies whether to use CPU or GPU. When set to auto CNTK picks the best available device. Set it to -1 to use the CPU or to a value >=0 to use a specific GPU. The modelPath defines where to store the intermediate and final trained models. In this example it uses the ModelDir variable defined at the beginning of the configuration file.

The three main configuration blocks for training define the network itself and the parameters for the training algorithm and the data reader.

  • Network builder - here you define the topology and the details of the network such as the size and number of layers and the type of nodes. You can use the Simple Network Builder or the [NDL Network Builder](Network Definition Language (NDL)). Please refer to the corresponding wiki pages for details.
  • SGD - this block lets you parameterize the training algorithm (stochastic gradient descent). Options include using momentum, adaptive learning rate, adaptive minibatch size or parallel training. See SGD block for more details.
  • reader - the reader block defines which reader to use and where the corresponding input files are. CNTK provides several data readers for different formats and tasks (see Reader block).

Finally, the line command = "TIMIT_TrainNDL" specifies which of the defined tasks to execute. To execute several tasks consecutively, e.g. training and evaluation, simply add more tasks to the command separated by a colon.

Evaluating a trained model

TODO

Using a trained model in your own solution

TODO

Clone this wiki locally