We begin the training process by creating the network in the workspace and initializing all the parameter blobs of the network in the workspace. This is done by calling the workspace RunNetOnce method:
# The parameter initialization network only needs to be run once.
workspace.RunNetOnce(train_model.param_init_net)
Next, we ask Caffe2 to create the network in memory:
# Creating an actual network as a C++ object in memory.
# We need this as the object is going to be used a lot
# so we avoid creating an object every single time it is used.
workspace.CreateNet(train_model.net, overwrite=True)
We are finally ready to train. We iterate a predetermined number of times and, in each iteration, we use the workspace RunNet method to run a forward pass and a backward pass.
Training a small network such as our LeNet model is fast both on CPU and GPU. However, many of...