Train a custom Object Detection model
Here, we will see how to perform transfer learning from a pre-trained model on your own dataset the easiest way ever !
TL;DR
If you just want to skip explanations and just start training your model, we have cooked a notebook just for you that you can open in Colab.
Click here to access the notebook.
Installation
First we need to install the picsellia
modules to get started.
And then install one of the following package whether you want to work with Tensorflow 1 or Tensorflow 2.
For the sake of our tutorial, we will use the picsellia_tf2
package, but the methods are nearly the same with the picsellia_tf1
package, you can check out the reference to learn more about how each module works.
Now that we are all set, let's get started !
Initialize our client
In order for your code to interact with the platform you need to start with those lines.
Ok, those first lines might need some explanations.
The Client
is the main Picsell.ia class, it will be used in every tutorials. You can check the reference here. The Client is for general use that's why here we initialize the subclass Experiment in order to focus on the experiment part of Picsell.ia.
pxl_utils
and pxl_tf
are the only two modules we need to perform training with Tensorflow.
You can find your api_token
in your profile on the platform, see this.
This tutorial assumes that you have created your first project, please refer to this tutorial if it's not the case.
You should see a greeting message in your console.
Now that we are connected to Picsell.ia, let's get down to real business.
Initialize an experiment
Checkout an existing experiment
If you have already created an experiment on the platform and chose a base model, you might want to retrieve it to launch your training and not create a new experiment, to do this you can call the following method
Let's explain the parameters :
'my-new-model' is obviously the name of the experiment you created earlier
tree
, setting this parameter to True will create the folder structure needed to store and organize all files issued from training (records, checkpoints, config, saved_model ...)with_file
, this parameters is set to True to fetch on your machine all the files stored under your experiment (checkpoints, config...)
Create a new experiment
If you want to log and store everything you create or observe during training, you have to create what we call an experiment.
Check out this page to learn more about the experiment system.
Now we can see that our experiment has been created and that we have retrieved all the assets from the efficientdet network to start our training :
Prepare for training
Now that we have created our experiment we need to do a few more steps before we can train, i'm sure you've guessed them :
Download annotations
Download images
Perform a train/test split
Create tfrecords (data placeholder optimized for training)
Edit the config file (needed to tune our experiment)
Here are the functions that will perform those actions, if you need more information please check the reference here.
Now let's fetch the default parameters for our mode, if you want to change some, don't forget to log them back afterward !
Train
Now we can call this simple method to run the training
Evaluate
Call this method to run an evaluation on all our test images
Export the model
Now we can export our model so we can load it to perform inference later on
Run inference
Let's try our model on a few images to check the results
Log and store
Nice job ! We have performed a complete training in just a few steps, now we will log our metrics and logs to the platform and store our file assets so we can restore it in our next iteration:
Last updated
Was this helpful?