Skip to main content

Google Colab Setup

In this section, you will learn how to train your model using Google Colab.

Prerequisites

Before getting started, make sure you have:

  • A Google Account to use Colab.
  • Note: Sometimes enterprises block the Colab service of Google. In such cases, use Tracebloc locally and run it from your Jupyter Notebook.

Instructions

1. Open Colab

  • Open Google Colab by clicking on the icon in the top right corner in our web application.

Open Colab

2. Copy the Notebook to your Drive

You don't have permission to save changes to the original notebook. Therefore, create a copy of the notebook and work on it instead.

Copy to Drive

3. Upload Model and Weights to Colab Session Storage

Upload the models and weights that you want to work with to the Colab session storage. At the end of the Colab session, the models and weights will be deleted from the session storage.

Colab Session Storage

4. Follow the Five-Step Guide

In this five-step guide, you will learn how to train your ML models on Tracebloc's privacy-preserving ML infrastructure.

4.1 Connect to Tracebloc

Connect to Tracebloc by running all cells in the notebook in order.

Start Guide

4.2 Upload Model & Weights File

  • To upload your model and weights file, make sure that your model meets our Model Structure Requirements.
  • You can find sample models to test in our Tracebloc Model Zoo.
  • Also, make sure that the model file name follows the convention: if the model file name is "model.py", the model weight file name should be "model_weights.pkl" for tensorflow or ""model_weights.pth" for pytorch.
  • If you want to upload model with pre-trained weights set weights arugment value as True, else the default value is False.
user.uploadModel('filename') # (model, weights=True)

In this step, you will link the uploaded model to the dataset you would like to train on. To do this, you can use the linkModelDataset method of the user object and pass in the dataset ID as a parameter.

trainingObject = user.linkModelDataset('datasetID') # link dataset to uploaded model in previous step

You can find the dataset id on our web application:

Data ID

The dataset and model need to match with respect to the number of classes. For more details click here.

4.4 Set Training Plan

In this step, you can set the training plan for your model by specifying various parameters such as the number of epochs, optimizer, learning rate, etc. Here's an example of how to set a parameter:

trainingObject.parameter_name(value)
# example trainingObject.epochs(5)
# example trainingObject.optimizer('sgd')

For more information on each parameter's value follow docstring.

Display the training plan

trainingObject.getTrainingPlan() # will display all parameters

Reset the training plan

trainingObject.resetTrainingPlan() # will reset all parameters
All training parameters
 Training Description

experimentName: Give your experiment a name for easy colaboration with your peers! :)
modelName: densenet
objective:

Dataset Parameters

datasetId: DKbtefZy
totalDatasetSize: 150
allClasses: {'car': 65, 'traffic light': 42, 'traffic sign': 43}

trainingDatasetSize: 150
trainingClasses: {'car': 65, 'traffic light': 42, 'traffic sign': 43}
imageShape: 224
imageType: rgb
seed: False

Training Parameters

epochs: 10
cycles: 1
batchSize: 16
validation_split: 0.06

Hyperparameters

optimizer: sgd
lossFunction: {'type': 'standard', 'value': 'categorical_crossentropy'}
learningRate: {'type': 'constant', 'value': 0.001}
layersFreeze:
earlystopCallback: {}
reducelrCallback: {}
modelCheckpointCallback: {}
terminateOnNaNCallback: {}

Augmentation Parameters

brightness_range: None
channel_shift_range: 0.0
cval: 0.0
fill_mode: nearest
height_shift_range: 0.0
horizontal_flip: False
rescale: None
rotation_range: 0
samplewise_center: False
samplewise_std_normalization: False
shear_range: 0.0
shuffle: True
vertical_flip: False
width_shift_range: 0.0
zoom_range: 0.0

4.5 Start Training

Once you have linked your model with the dataset and set the training plan, you can start the training process by calling the start method:

trainingObject.start() # start the experiment as configured above

This will start the training process and you can monitor the progress of your model via clicking the link of experiment provided.

Logout

You can log out to ensure the security of your account. To do this, simply call the logout method:

user.logout()