README.md 3.59 KB
Newer Older
zhe chen's avatar
zhe chen committed
1
2
# InternImage for Object Detection

zhe chen's avatar
zhe chen committed
3
This folder contains the implementation of the InternImage for object detection.
zhe chen's avatar
zhe chen committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Our detection code is developed on top of [MMDetection v2.28.1](https://github.com/open-mmlab/mmdetection/tree/v2.28.1).

## Usage

### Install

- Clone this repo:

```bash
git clone https://github.com/OpenGVLab/InternImage.git
cd InternImage
```

- Create a conda virtual environment and activate it:

```bash
zhe chen's avatar
zhe chen committed
21
conda create -n internimage python=3.9
zhe chen's avatar
zhe chen committed
22
23
24
25
26
conda activate internimage
```

- Install `CUDA>=10.2` with `cudnn>=7` following
  the [official installation instructions](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html)
27
- Install `PyTorch>=1.10.0` and `torchvision>=0.9.0` with `CUDA>=10.2`:
zhe chen's avatar
zhe chen committed
28
29

For examples, to install torch==1.11 with CUDA==11.3:
zhe chen's avatar
zhe chen committed
30

zhe chen's avatar
zhe chen committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
```bash
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113  -f https://download.pytorch.org/whl/torch_stable.html
```

- Install `timm==0.6.11` and `mmcv-full==1.5.0`:

```bash
pip install -U openmim
mim install mmcv-full==1.5.0
pip install timm==0.6.11 mmdet==2.28.1
```

- Install other requirements:

```bash
pip install opencv-python termcolor yacs pyyaml scipy
```

- Compile CUDA operators
zhe chen's avatar
zhe chen committed
50

zhe chen's avatar
zhe chen committed
51
52
53
54
55
56
```bash
cd ./ops_dcnv3
sh ./make.sh
# unit test (should see all checking is True)
python test.py
```
zhe chen's avatar
zhe chen committed
57

yeshenglong1's avatar
yeshenglong1 committed
58
59
- You can also install the operator using .whl files

yeshenglong1's avatar
yeshenglong1 committed
60
[DCNv3-1.0-whl](https://github.com/OpenGVLab/InternImage/releases/tag/whl_files)
zhe chen's avatar
zhe chen committed
61

62
### Data Preparation
zhe chen's avatar
zhe chen committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76

Prepare COCO according to the guidelines in [MMDetection v2.28.1](https://github.com/open-mmlab/mmdetection/blob/master/docs/en/1_exist_data_model.md).

### Evaluation

To evaluate our `InternImage` on COCO val, run:

```bash
sh dist_test.sh <config-file> <checkpoint> <gpu-num> --eval bbox segm
```

For example, to evaluate the `InternImage-T` with a single GPU:

```bash
77
python test.py configs/coco/mask_rcnn_internimage_t_fpn_1x_coco.py checkpoint_dir/det/mask_rcnn_internimage_t_fpn_1x_coco.pth --eval bbox segm
zhe chen's avatar
zhe chen committed
78
79
80
81
82
```

For example, to evaluate the `InternImage-B` with a single node with 8 GPUs:

```bash
83
sh dist_test.sh configs/coco/mask_rcnn_internimage_b_fpn_1x_coco.py checkpoint_dir/det/mask_rcnn_internimage_b_fpn_1x_coco.py 8 --eval bbox segm
zhe chen's avatar
zhe chen committed
84
85
86
87
88
89
90
91
92
93
94
95
96
```

### Training on COCO

To train an `InternImage` on COCO, run:

```bash
sh dist_train.sh <config-file> <gpu-num>
```

For example, to train `InternImage-T` with 8 GPU on 1 node, run:

```bash
97
sh dist_train.sh configs/coco/mask_rcnn_internimage_t_fpn_1x_coco.py 8
zhe chen's avatar
zhe chen committed
98
99
```

100
### Manage Jobs with Slurm
zhe chen's avatar
zhe chen committed
101
102
103
104

For example, to train `InternImage-L` with 32 GPU on 4 node, run:

```bash
105
GPUS=32 sh slurm_train.sh <partition> <job-name> configs/coco/cascade_internimage_xl_fpn_3x_coco.py work_dirs/cascade_internimage_xl_fpn_3x_coco
zhe chen's avatar
zhe chen committed
106
```
Weiyun1025's avatar
Weiyun1025 committed
107
108
109
110

### Export

To export a detection model from PyTorch to TensorRT, run:
zhe chen's avatar
zhe chen committed
111

Weiyun1025's avatar
Weiyun1025 committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
```shell
MODEL="model_name"
CKPT_PATH="/path/to/model/ckpt.pth"

python deploy.py \
    "./deploy/configs/mmdet/instance-seg/instance-seg_tensorrt_dynamic-320x320-1344x1344.py" \
    "./configs/coco/${MODEL}.py" \
    "${CKPT_PATH}" \
    "./deploy/demo.jpg" \
    --work-dir "./work_dirs/mmdet/instance-seg/${MODEL}" \
    --device cuda \
    --dump-info
```

For example, to export `mask_rcnn_internimage_t_fpn_1x_coco` from PyTorch to TensorRT, run:
zhe chen's avatar
zhe chen committed
127

Weiyun1025's avatar
Weiyun1025 committed
128
129
130
131
132
133
134
135
136
137
138
139
140
```shell
MODEL="mask_rcnn_internimage_t_fpn_1x_coco"
CKPT_PATH="/path/to/model/ckpt/mask_rcnn_internimage_t_fpn_1x_coco.pth"

python deploy.py \
    "./deploy/configs/mmdet/instance-seg/instance-seg_tensorrt_dynamic-320x320-1344x1344.py" \
    "./configs/coco/${MODEL}.py" \
    "${CKPT_PATH}" \
    "./deploy/demo.jpg" \
    --work-dir "./work_dirs/mmdet/instance-seg/${MODEL}" \
    --device cuda \
    --dump-info
```