Skip to content

Commit

Permalink
#7 Added configs for tuning on custom dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
Peterande committed Oct 25, 2024
1 parent 681fbb9 commit a7c3c86
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 trai
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_custom.yml --test-only -r model.pth
```

4. [Optional] Modify Class Mappings:
4. Tuning on Custom Dataset
```shell
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_obj2custom.yml --use-amp --seed=0 -t model.pth
```

5. [Optional] Modify Class Mappings:

When using the Objects365 pre-trained weights to train on your custom dataset, the example assumes that your dataset only contains the classes `'Person'` and `'Car'`. For faster convergence, you can modify `self.obj365_ids` in `src/solver/_solver.py` as follows:

Expand Down
7 changes: 6 additions & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,12 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 trai
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_custom.yml --test-only -r model.pth
```

4. [可选] 修改类映射:
4. 在自定义数据集上微调
```shell
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_obj2custom.yml --use-amp --seed=0 -t model.pth
```

5. [可选] 修改类映射:

在使用 Objects365 预训练权重训练自定义数据集时,示例中假设自定义数据集仅有 `'Person'` 和 `'Car'` 类,您可以将其替换为数据集中对应的任何类别。为了加快收敛,可以在 `src/solver/_solver.py` 中修改 `self.obj365_ids`,如下所示:

Expand Down
52 changes: 52 additions & 0 deletions configs/dfine/custom/objects365/dfine_hgnetv2_l_obj2custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
__include__: [
'../../dataset/custom_detection.yml',
'../../runtime.yml',
'../include/dataloader.yml',
'../include/optimizer.yml',
'../include/dfine_hgnetv2.yml',
]

output_dir: ./output/dfine_hgnetv2_l_obj2custom


DFINE:
backbone: HGNetv2

HGNetv2:
name: 'B4'
return_idx: [1, 2, 3]
freeze_stem_only: True
freeze_at: 0
freeze_norm: True

optimizer:
type: AdamW
params:
-
params: '^(?=.*backbone)(?!.*norm|bn).*$'
lr: 0.0000125
-
params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn)).*$'
weight_decay: 0.

lr: 0.00025
betas: [0.9, 0.999]
weight_decay: 0.000125


epoches: 36 # Early stop
train_dataloader:
dataset:
transforms:
policy:
epoch: 30
collate_fn:
stop_epoch: 30
ema_restart_decay: 0.9999
scale_ori_repeat: 4

ema:
warmups: 0

lr_warmup_scheduler:
warmup_duration: 0
65 changes: 65 additions & 0 deletions configs/dfine/custom/objects365/dfine_hgnetv2_m_obj2custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
__include__: [
'../../dataset/custom_detection.yml',
'../../runtime.yml',
'../include/dataloader.yml',
'../include/optimizer.yml',
'../include/dfine_hgnetv2.yml',
]

output_dir: ./output/dfine_hgnetv2_m_obj2custom


DFINE:
backbone: HGNetv2

HGNetv2:
name: 'B2'
return_idx: [1, 2, 3]
freeze_at: -1
freeze_norm: False
use_lab: True

DFINETransformer:
num_layers: 4 # 5 6
eval_idx: -1 # -2 -3

HybridEncoder:
in_channels: [384, 768, 1536]
hidden_dim: 256
depth_mult: 0.67

optimizer:
type: AdamW
params:
-
params: '^(?=.*backbone)(?!.*norm|bn).*$'
lr: 0.000025
-
params: '^(?=.*backbone)(?=.*norm|bn).*$'
lr: 0.000025
weight_decay: 0.
-
params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn|bias)).*$'
weight_decay: 0.

lr: 0.00025
betas: [0.9, 0.999]
weight_decay: 0.000125


epoches: 56 # Early stop
train_dataloader:
dataset:
transforms:
policy:
epoch: 48
collate_fn:
stop_epoch: 48
ema_restart_decay: 0.9999
scale_ori_repeat: 6

ema:
warmups: 0

lr_warmup_scheduler:
warmup_duration: 0
66 changes: 66 additions & 0 deletions configs/dfine/custom/objects365/dfine_hgnetv2_s_obj2custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
__include__: [
'../../dataset/custom_detection.yml',
'../../runtime.yml',
'../include/dataloader.yml',
'../include/optimizer.yml',
'../include/dfine_hgnetv2.yml',
]

output_dir: ./output/dfine_hgnetv2_s_obj2custom


DFINE:
backbone: HGNetv2

HGNetv2:
name: 'B0'
return_idx: [1, 2, 3]
freeze_at: -1
freeze_norm: False
use_lab: True

DFINETransformer:
num_layers: 3 # 4 5 6
eval_idx: -1 # -2 -3 -4

HybridEncoder:
in_channels: [256, 512, 1024]
hidden_dim: 256
depth_mult: 0.34
expansion: 0.5

optimizer:
type: AdamW
params:
-
params: '^(?=.*backbone)(?!.*norm|bn).*$'
lr: 0.000125
-
params: '^(?=.*backbone)(?=.*norm|bn).*$'
lr: 0.000125
weight_decay: 0.
-
params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn|bias)).*$'
weight_decay: 0.

lr: 0.00025
betas: [0.9, 0.999]
weight_decay: 0.000125


epoches: 64 # Early stop
train_dataloader:
dataset:
transforms:
policy:
epoch: 56
collate_fn:
stop_epoch: 56
ema_restart_decay: 0.9999
scale_ori_repeat: 10

ema:
warmups: 0

lr_warmup_scheduler:
warmup_duration: 0
61 changes: 61 additions & 0 deletions configs/dfine/custom/objects365/dfine_hgnetv2_x_obj2custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
__include__: [
'../../dataset/custom_detection.yml',
'../../runtime.yml',
'../include/dataloader.yml',
'../include/optimizer.yml',
'../include/dfine_hgnetv2.yml',
]

output_dir: ./output/dfine_hgnetv2_x_obj2custom


DFINE:
backbone: HGNetv2

HGNetv2:
name: 'B5'
return_idx: [1, 2, 3]
freeze_stem_only: True
freeze_at: 0
freeze_norm: True

HybridEncoder:
# intra
hidden_dim: 384
dim_feedforward: 2048

DFINETransformer:
feat_channels: [384, 384, 384]
reg_scale: 8

optimizer:
type: AdamW
params:
-
params: '^(?=.*backbone)(?!.*norm|bn).*$'
lr: 0.0000025
-
params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn)).*$'
weight_decay: 0.

lr: 0.00025
betas: [0.9, 0.999]
weight_decay: 0.000125


epoches: 36 # Early stop
train_dataloader:
dataset:
transforms:
policy:
epoch: 30
collate_fn:
stop_epoch: 30
ema_restart_decay: 0.9999
scale_ori_repeat: 3

ema:
warmups: 0

lr_warmup_scheduler:
warmup_duration: 0

0 comments on commit a7c3c86

Please sign in to comment.