Getting Started with DiffusionDet

Introduction

This is the official code of DiffusionDet for Polyp Detection. We extend DiffusionDet for testing the result of using this new method instead of using YOLO...

Installation

The codebases are built on top of Detectron2, Sparse R-CNN, and denoising-diffusion-pytorch. Thanks very much.

Requirements

  • Linux or macOS with Python ≥ 3.6
  • PyTorch ≥ 1.9.0 and torchvision that matches the PyTorch installation. You can install them together at pytorch.org to make sure of this
  • OpenCV is optional and needed by demo and visualization

Steps

  1. Install Detectron2 following https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md#installation.

  2. Prepare datasets

cd PolypsSet
python devide_train_set.py
python devide_test_set.py
cd ..
  1. Prepare pretrain models

DiffusionDet uses three backbones including ResNet-50, ResNet-101 and Swin-Base. The pretrained ResNet-50 model can be downloaded automatically by Detectron2. We also provide pretrained ResNet-101 and Swin-Base which are compatible with Detectron2. Please download them to DiffusionDet_ROOT/models/ before training:

mkdir models
cd models
# ResNet-101
wget https://github.com/ShoufaChen/DiffusionDet/releases/download/v0.1/torchvision-R-101.pkl

# Swin-Base
wget https://github.com/ShoufaChen/DiffusionDet/releases/download/v0.1/swin_base_patch4_window7_224_22k.pkl

cd ..

Thanks for model conversion scripts of ResNet-101 and Swin-Base.

  1. Train DiffusionDet
python train_net.py --num-gpus 1 \
    --config-file configs/diffdet.polyp.res50.yaml
  1. Evaluate DiffusionDet
python train_net.py --num-gpus 8 \
    --config-file configs/diffdet.polyp.res50.yaml \
    --eval-only MODEL.WEIGHTS path/to/model.pth
  • Evaluate with 4 refinement steps by setting MODEL.DiffusionDet.SAMPLE_STEP 4.

Inference Demo with Pre-trained Models

We provide a command line tool to run a simple demo of a set of images following Detectron2.

python demo.py --config-file configs/diffdet.coco.res50.yaml \
    --input images_folder --opts MODEL.WEIGHTS diffdet_polyp_res50.pth