Fitting the network

In order to run the training process, we will call the mx.fit function. It provides different sets of parameters and in the following case, we will be using a number of them:

mx.fit(nnet, mx.ADAM(), train_data_provider, eval_data = validation_data_provider, n_epoch = 100, callbacks = [mx.speedometer()]);

In the preceding example, we have done the following:

  1. nnet corresponds to the network we created before.
  2. mx.ADAM corresponds to a weight update function and ADAM is proven to converge networks extremely quickly.
  3. Next, we pass our train data provider consisting of images and labels.
  4. We set the eval_data parameter to monitor the performance of our network on validation_data_provider.
  5. n_epoch corresponds to the number of passes over the entire database.
  6. callbacks is used for additional functions that we would like to evaluate. mx.speedometer is providing information on the number of records processed per second.

The results of running the fit function are the following:

Main> 
INFO: Start training on MXNet.mx.Context[CPU0]
INFO: Initializing parameters...
INFO: Creating KVStore...
INFO: TempSpace: Total 3 MB allocated on CPU0
INFO: Start training...
INFO: Speed: 15649.83 samples/sec
INFO: == Epoch 001/100 ==========
INFO: ## Training summary
INFO: accuracy = 0.6949
INFO: time = 3.2204 seconds
INFO: ## Validation summary
INFO: accuracy = 0.8380
INFO: Speed: 49859.40 samples/sec
INFO: == Epoch 002/100 ==========
...
INFO: == Epoch 099/100 ==========
INFO: ## Training summary
INFO: accuracy = 0.9327
INFO: time = 1.0534 seconds
INFO: ## Validation summary
INFO: accuracy = 0.9332
INFO: Speed: 50553.82 samples/sec
INFO: == Epoch 100/100 ==========
INFO: ## Training summary
INFO: accuracy = 0.9327
INFO: time = 0.9950 seconds
INFO: ## Validation summary
INFO: accuracy = 0.9331
INFO: Finish training on MXNet.mx.Context[CPU0]

So, in 100 epochs, we have reached 93.3% accuracy. Great results!