Colab: How to Train Detectron2 on Custom Object Detection Data

本教程将指导如何在Detectron2的Colab笔记本中训练自定义目标检测。首先下载detectron.ipynb教程代码,然后安装依赖,启用GPU资源,下载标注数据,注册数据到Detectron2,可视化训练数据,配置训练参数,开始训练,评估模型性能,并在测试图像上运行推理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 colab, we can

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值