Colab: How to Train Detectron2 on Custom Object Detection Data
In this turorial, we will go through how to train Detectron2 to detect custom objects in this Detectron2 Colab notebook. Before we start it, please download the detectron.ipynb file which I uploaded on GoogleDrive, here is the link: tutorial code
1. Install Detectron2 dependencies
# install dependencies: (use cu101 because colab has CUDA 10.1)
!pip install -U torch==1.5 torchvision==0.6 -f https://download.pytorch.org/whl/cu101/torch_stable.html
!pip install cython pyyaml==5.1
!pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
!gcc --version
# opencv is pre-installed on colab
# install detectron2:
!pip install detectron2==0.1.3 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.5/index.html
2. Import libraries
Google Colab provides us with free GPU resources so make sure to enable them by checking Runtime --> Change runtime type --> GPU.
# Remember restart your runtime prior to this, to let your installation take effect
# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
# import some common libraries
import numpy as np
import cv2
import random
from google.colab.patches import cv2_imshow
# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog
from detectron2.data.catalog import DatasetCatalog
3. Download detection data
For the very first detection task, I recommend this website to download some labeled dataset and this dataset can be download in many format such as COCO JSON, CreateML JSON and Pascal VOC XML. The website is Roboflow dataset. In col