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

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ModuleNotFoundError: No module named 'detectron2'的错误通常表示您的Python环境中缺少detectron2模块。您可以按照以下步骤来解决这个问题: 1. 确保您已经安装了detectron2模块。可以尝试使用命令`pip install detectron2`来安装它。 2. 如果您已经安装了detectron2模块但仍然出现此错误,请检查您的Python环境是否正确配置。您可以尝试在命令行中运行`python`,然后输入`import detectron2`来验证模块是否正确安装和可用。 3. 如果模块安装正确但仍然无法导入,请检查您的项目或脚本中是否正确引用了detectron2模块。确保您的`import`语句正确,并且模块名拼写正确。 4. 如果您是在虚拟环境中工作,请确保您已经激活了该虚拟环境。您可以通过运行`source venv/bin/activate`(对于Linux和Mac)或`venv\Scripts\activate`(对于Windows)来激活虚拟环境。 5. 如果您在使用Anaconda环境,请确保您已经在正确的环境中安装了detectron2模块。您可以尝试使用命令`conda install -c conda-forge detectron2`来安装它。 请根据您的具体情况尝试上述方法来解决ModuleNotFoundError: No module named 'detectron2'的错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Colab运行detectron2 demo](https://blog.csdn.net/qq_37003230/article/details/118771955)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [测试detectron2:ModuleNotFoundError: No module named ‘win32con](https://blog.csdn.net/weixin_44696646/article/details/124554594)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Python模块导入出现ModuleNotFoundError: No module named ‘***’](https://download.csdn.net/download/weixin_38658085/14885867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值