Tutorial: UAV landcover classification with fastai & Google Colab

Christoph Rieke
5 min readJan 3, 2020

This tutorial lets you train a land cover classification model with high-resolution Dronedeploy UAV imagery using fastai and Google Colab. No requirements, in-browser, with a GPU.

Dronedeploy recently released the “DroneDeploy Machine Learning Segmentation” dataset and baseline model. The dataset consists of super crisp 10cm resolution UAV images for 51 areas of interest all over the US, as well as pixel masks for 6 categories (building, clutter, vegetation, water, ground, car). This tutorial takes the excellent Dronedeploy fastai implementation, puts it into Google Colab and gives beginner-friendly step for step instructions to make it even more accessible.

Colab is Google’s variant of “Jupyter notebook in the cloud”, it offers free GPU access to every user. To train the model open this prepared Google Colab notebook, click “Open in playground mode” on the top left and follow the instructions below.

1. First activate GPU access: In the Colab main menu, go to “Runtime”, “Change runtime type” and under “Hardware accelerator” select “GPU”.

2. Select the first notebook cell and run it via the “Run Cell” button (or press Shift + Enter). This will download the Dronedeploy github repository.

3. Continue with the next cells to change the working directory to the downloaded folder and install the required Python libraries.

4. This step is optional: The Dronedeploy implementation uses wandb.com to track the training progress. If you want to use it, run the cell and follow the appearing instructions (create an account and copy your APIkey), otherwise just skip this cell and go to step 5.

wandb is a platform that visualizes and keeps track of all your experiment data in one place. It’s free for individuals. I discovered it through this Dronedeploy repo and am very impressed. wandb integrates with a few lines of code in your deep learning framework of choice and saves the training progress & logs, network & system parameters, uploads the best model etc. You can even submit your run to the Dronedeploy dataset’s leaderboard!

5. Finally, prepare the data and train the model via:

This will download the “dataset-sample” (direct download link), a subset containing images for 3 of the 51 areas of interest. The images and labels are cut to image chips of 256x256 pixels. The process then downloads a resnet18 base model and start the training process for semantic segmentation via a U-Net model. After the training is finished, the model accuracy is evaluated on a set of hold-out validation chips. The whole process will take a couple of minutes. The evaluation metrics are printed to the notebook and are discoverable in more detail in wandb. To see the predicted validation images, in Colaboratory, go to “View”, “Table of contents”. In the sidebar, under the “Files” tab go to “content/dd-ml-segmentation-benchmark/predictions”.

UAV RGB image and Ground Truth labels (left) and Predicted Image (right) (trained on the full dataset with default settings)

Running the training on the full Dronedeploy dataset with the default settings takes 3 hours and yields an F1-score of 0.77. The Dronedeploy implementation acts as a baseline model, there are many potential improvements, e.g. incorporating elevation data (also included in the dataset!), data augmentation, tuned model hyperparameters etc.
If you want to train the model with the full dataset, open “content/dd-ml-segmentation-benchmark/main_fastai.py” and uncomment ‘dataset-medium’ on line 11. Then rerun the notebook. Pay attention that you come back to the notebook browser tab from time to time as the Colab kernel shuts down after 90min idle. Tip: Google Colab is great for prototyping and sharing your work, but less convenient for larger scale tasks, as one session lasts for max. 12 hours.

As a final recommendation, take a look at the scripts in the Dronedeploy repository! The clean code and fastai’s abstractions make it easy to follow the process step for step. Further ressources I can recommend are rastervision, solaris and robosat.pink, all three are easy to use Python libraries for geospatial deep learning.

You can follow me on chrieke.com and Twitter @ chrieke